refactor: remove beta supplier stack and update cdk stack with docker installation and EC2 configuration

This commit is contained in:
vickytechkey 2026-09-12 18:38:56 +05:30
parent 7e2ccb4eb3
commit 34bb040bd7
3 changed files with 17 additions and 139 deletions

View file

@ -51,6 +51,7 @@ export class AwsCdkStack extends cdk.Stack {
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(8080), 'Allow Django Beta Backend (Public)');
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(8090), 'Allow Django Production Backend (Public)');
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(8082), 'Allow Django Customer Backend (Public)');
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(9003), 'Allow Port 9003 (Public)');
// pgAdmin 4 Web UI - Open to public
securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(5050), 'Allow pgAdmin 4 Web UI IPv4');
@ -149,7 +150,7 @@ export class AwsCdkStack extends cdk.Stack {
// Create CloudFront Distribution for the S3 bucket
const distribution = new cloudfront.Distribution(this, 'SupplierDocumentDistribution', {
defaultBehavior: {
origin: new origins.S3Origin(supplierDocumentBucket),
origin: origins.S3BucketOrigin.withOriginAccessControl(supplierDocumentBucket),
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
@ -161,21 +162,22 @@ export class AwsCdkStack extends cdk.Stack {
supplierDocumentBucket.grantReadWrite(role);
// 3. Define the EC2 Instance (t4g.medium)
const instance = new ec2.Instance(this, 'internalsInstance', {
const instance = new ec2.Instance(this, 'internalsInstanceV2', {
vpc,
vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.MEDIUM),
machineImage: ec2.MachineImage.fromSsmParameter(
'/aws/service/canonical/ubuntu/server/24.04/stable/current/arm64/hvm/ebs-gp3/ami-id'
),
machineImage: ec2.MachineImage.genericLinux({
'ap-south-2': 'ami-00040d84957540625',
}),
securityGroup,
role,
keyName: 'vignesh_tipro_apsouth2',
keyPair: ec2.KeyPair.fromKeyPairName(this, 'KeyPair', 'vignesh_tipro_apsouth2'),
detailedMonitoring: true,
blockDevices: [
{
deviceName: '/dev/sda1',
volume: ec2.BlockDeviceVolume.ebs(50, { // 50GB Root Volume
volume: ec2.BlockDeviceVolume.ebsFromSnapshot('snap-05ca1db4b2038f7d6', {
volumeSize: 50,
volumeType: ec2.EbsDeviceVolumeType.GP3,
}),
},
@ -194,6 +196,14 @@ export class AwsCdkStack extends cdk.Stack {
'set -e',
'apt-get update -y',
'apt-get install -y ca-certificates curl gnupg lsb-release wget python3 python3-pip python3-venv git build-essential',
'# Install Docker',
'install -m 0755 -d /etc/apt/keyrings',
'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg',
'chmod a+r /etc/apt/keyrings/docker.gpg',
'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null',
'apt-get update -y',
'apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin',
'usermod -aG docker ubuntu',
'EOF',
'chmod +x /home/ubuntu/basic_requirements/install.sh',
'/home/ubuntu/basic_requirements/install.sh',

View file

@ -1,73 +0,0 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
export class BetaSupplierSiteStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// 1. Create S3 Bucket for Website hosting
const websiteBucket = new s3.Bucket(this, 'BetaSupplierSiteBucket', {
bucketName: `betasuppliersite-${this.account}-${this.region}`,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, // Secure by default, OAI will be used
encryption: s3.BucketEncryption.S3_MANAGED,
});
const ec2Origin = new origins.HttpOrigin('ec2-16-113-57-127.ap-south-2.compute.amazonaws.com', {
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTP_ONLY,
httpPort: 8080,
});
// 2. Create CloudFront Distribution
// origins.S3Origin will automatically create an Origin Access Identity (OAI)
// and update the S3 bucket policy to allow access only from this CloudFront distribution.
const distribution = new cloudfront.Distribution(this, 'BetaSupplierSiteDistribution', {
defaultRootObject: 'index.html',
defaultBehavior: {
origin: new origins.S3Origin(websiteBucket),
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
},
additionalBehaviors: {
'/api/*': {
origin: ec2Origin,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER,
},
},
errorResponses: [
{
httpStatus: 404,
responseHttpStatus: 200, // Return 200 for SPAs
responsePagePath: '/index.html',
ttl: cdk.Duration.seconds(0),
},
{
httpStatus: 403,
responseHttpStatus: 200, // Return 200 for SPAs
responsePagePath: '/index.html',
ttl: cdk.Duration.seconds(0),
}
]
});
// Outputs
new cdk.CfnOutput(this, 'BetaSupplierSiteBucketName', {
value: websiteBucket.bucketName,
description: 'The name of the S3 bucket for the betasupplier site',
});
new cdk.CfnOutput(this, 'BetaSupplierSiteCloudFrontDomainName', {
value: distribution.distributionDomainName,
description: 'The domain name of the CloudFront distribution for betasupplier site',
});
}
}

View file

@ -1,59 +0,0 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
export class BetaSupplierSiteStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// 1. Create S3 Bucket for Website hosting
const websiteBucket = new s3.Bucket(this, 'BetaSupplierSiteBucket', {
bucketName: `betasuppliersite-${this.account}-${this.region}`,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, // Secure by default, OAI will be used
encryption: s3.BucketEncryption.S3_MANAGED,
});
// 2. Create CloudFront Distribution
// origins.S3Origin will automatically create an Origin Access Identity (OAI)
// and update the S3 bucket policy to allow access only from this CloudFront distribution.
const distribution = new cloudfront.Distribution(this, 'BetaSupplierSiteDistribution', {
defaultRootObject: 'index.html',
defaultBehavior: {
origin: new origins.S3Origin(websiteBucket),
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
},
errorResponses: [
{
httpStatus: 404,
responseHttpStatus: 200, // Return 200 for SPAs
responsePagePath: '/index.html',
ttl: cdk.Duration.seconds(0),
},
{
httpStatus: 403,
responseHttpStatus: 200, // Return 200 for SPAs
responsePagePath: '/index.html',
ttl: cdk.Duration.seconds(0),
}
]
});
// Outputs
new cdk.CfnOutput(this, 'BetaSupplierSiteBucketName', {
value: websiteBucket.bucketName,
description: 'The name of the S3 bucket for the betasupplier site',
});
new cdk.CfnOutput(this, 'BetaSupplierSiteCloudFrontDomainName', {
value: distribution.distributionDomainName,
description: 'The domain name of the CloudFront distribution for betasupplier site',
});
}
}