This CDK project creates a trigger to copy files from a given S3 bucket to an existing EC2 server.
The solution uses an S3 notification event fired when a new file is created in the bucket to run a lambda function. The lambda function will get file details and run a python script through SSM Run Command to download the file to a specified folder and delete the S3 file after that.
In case of failure, the solution will send a alert to the specified email
- ec2InstanceId: Existing EC2 instance id
- ec2LocalFolder: EC2 folder to download S3 files
- s3BucketArn: Source S3 Bucket Arn
- s3BucketEventFilterSuffix: S3 event filter suffix (help)
- emailToNotify: Email to notify in case of failure
cdk deploy --parameters ec2InstanceId=EC2_INSTANCE_ID \
--parameters ec2LocalFolder=/tmp \
--parameters s3BucketArn=arn:aws:s3:::BUCKET_NAME \
--parameters s3BucketEventFilterSuffix=pdf \
--parameters emailToNotify=email@sample.com /
Detail: Make sure your existing EC2 role has SSM permissions and the following permissions related with your S3 Bucket: "s3:GetObject", "s3:DeleteObject"
ProTip: The EC2 server needs to have the boto3 python library installed. If you don't already have it, you can install it with the command: pip3 install boto3
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation templatecdk destroy
removes the stack and all resources created by the stack