Deploy and host CV on a S3 bucket with public access URL exposed.
This project involves creating an AWS CDK stack to deploy a static website to an S3 bucket. The website contains a single file, cv.txt
, which is publicly accessible through the bucket's website URL. The deployment process involves syncing the local assets directory to the S3 bucket using the aws-cdk-lib/aws-s3-deployment
module. The stack outputs the bucket's ARN and website URL using cdk.CfnOutput
. The goal of the project is to provide a simple example of deploying a static website to S3 using AWS CDK.
cdk deploy
- Deploys the CDK stack to AWS, from there can access the public URLcdk destroy
- Destroys the CDK stack from AWS, to clean-up
This project uses the following AWS services:
- Amazon S3 - to store and serve static website files
- AWS CDK - to define infrastructure as code and deploy it
- AWS CloudFormation - to provision and manage AWS resources in a safe, repeatable manner
CDK stack written in TypeScript that creates an S3 bucket in AWS and deploys a static website to it.
Here's a breakdown of the main components of the stack:
-
const bucket = new s3.Bucket(this, 'CVBucket', {...})
: This creates a new S3 bucket with the specified properties. In this case, theautoDeleteObjects
property is set totrue
, which means that when the stack is deleted, the bucket and all its contents will be deleted as well. TheremovalPolicy
property is set toDESTROY
, which means that when the stack is deleted, the bucket and all its contents will be destroyed. ThepublicReadAccess
property is set totrue
, which means that the bucket and its contents will be publicly readable.- Bucket policy is defined that allows public access
-
new s3deploy.BucketDeployment(this, 'CVDeployment', {...})
: This creates a new deployment for the S3 bucket that was created in the previous step. It deploys the contents of the./assets
directory to the bucket, excluding all files except forcv.txt
. -
new cdk.CfnOutput(this, 'Bucket ARN', {...})
: This creates a new CloudFormation output that shows the ARN (Amazon Resource Name) of the S3 bucket created in step 1. -
new cdk.CfnOutput(this, 'Bucket URL', {...})
: This creates a new CloudFormation output that shows the URL of the S3 bucket created in step 1.
Overall, this stack creates an S3 bucket with public read access and deploys a static website to it. It also creates two CloudFormation outputs that show the ARN and URL of the bucket.
- Integrate CloudFront with the S3 bucket and benefit from edge locations for faster response all around the world
- Hook up Route53 with an alias record for custom domain to route traffic to CloudFront
Using aws-cdk-lib
v2 API where all AWS services are available as sub folders i.e. aws-cdk-lib/aws-s3
and aws-cdk-lib/aws-s3-deployment
.
Can use aws s3 cp DIRECTORY_OR_FILE s3://BUCKET_NAME
CLI command to manually add/put object into S3 bucket.