CodeCommit to Amazon S3

AWS CodeCommit → Amazon S3

Backup CodeCommit repos to S3 buckets.

This pattern implements the solution outlined at https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automate-event-driven-backups-from-codecommit-to-amazon-s3-using-codebuild-and-cloudwatch-events.html.
It uses a Lambda function and a CloudFormation Custom Resource to create the CodeBuild buildspec.yml template at deployment time, and the EventBridge and CodeBuild project described on the AWS Prescriptive Guidance.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Launch Stack

Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/codecommit-s3

Deploy

sam deploy --guided --capabilities CAPABILITY_NAMED_IAM


Testing

1. You can test the solution by accessing the Lambda console, finding the Lambda function, and clicking Test in the Code Source section.
2. You can also invoke the function from the CLI using aws lambda invoke --function-name ENTER_FUNCTION_NAME output.txt.
3. Go to the S3 console, locate the deployed S3 bucket, and view the object has been written.

Cleanup

1. Delete the stack: sam delete --stack-name STACK_NAME.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Created by:

Marcos Hauer

Marcos Hauer

I'm a Cloud Architect, SRE and AWS DevOps Consultant.