adding s3 and cloufront
This commit is contained in:
parent
b8943f4ead
commit
98f6568d13
1 changed files with 31 additions and 0 deletions
|
|
@ -4,6 +4,9 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
|
|||
import * as iam from 'aws-cdk-lib/aws-iam';
|
||||
import * as dlm from 'aws-cdk-lib/aws-dlm';
|
||||
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
|
||||
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 AwsCdkStack extends cdk.Stack {
|
||||
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
||||
|
|
@ -131,6 +134,29 @@ export class AwsCdkStack extends cdk.Stack {
|
|||
],
|
||||
}));
|
||||
|
||||
// Create the S3 bucket for supplier documents
|
||||
const supplierDocumentBucket = new s3.Bucket(this, 'BetaSupplierDocumentStorageBucket', {
|
||||
bucketName: 'betasupplierdocumentstorage',
|
||||
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
||||
autoDeleteObjects: true,
|
||||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
|
||||
encryption: s3.BucketEncryption.S3_MANAGED,
|
||||
});
|
||||
|
||||
// Create CloudFront Distribution for the S3 bucket
|
||||
const distribution = new cloudfront.Distribution(this, 'SupplierDocumentDistribution', {
|
||||
defaultBehavior: {
|
||||
origin: new origins.S3Origin(supplierDocumentBucket),
|
||||
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
||||
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
|
||||
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
|
||||
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
|
||||
},
|
||||
});
|
||||
|
||||
// Grant EC2 IAM role read/write permissions to the new S3 bucket
|
||||
supplierDocumentBucket.grantReadWrite(role);
|
||||
|
||||
// 3. Define the EC2 Instance (t4g.medium)
|
||||
const instance = new ec2.Instance(this, 'internalsInstance', {
|
||||
vpc,
|
||||
|
|
@ -307,6 +333,11 @@ export class AwsCdkStack extends cdk.Stack {
|
|||
value: dbSecret.secretArn,
|
||||
description: 'ARN of the DB credentials secret in Secrets Manager',
|
||||
});
|
||||
|
||||
new cdk.CfnOutput(this, 'SupplierDocumentCloudFrontDomain', {
|
||||
value: distribution.distributionDomainName,
|
||||
description: 'CloudFront Distribution Domain Name for Supplier Documents',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue