Running long-running scripts with CodeBuild

Amazon EventBridge → AWS CodeBuild → Amazon SNS

Create a CodeBuild project triggered by a scheduled EventBridge rule.

Developers sometimes encounter the 15-minute timeout limit for Lambda functions. This pattern demonstrates how to use AWS CodeBuild to run long-running scripts (scripts that run for more than 15 minutes) in a serverless application. This examples creates a CodeBuild project that runs a sample script triggered by a scheduled EventBridge rule, and a SNS topic to inform the completion of the CodeBuild project. A S3 bucket is also created to upload sample script.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/eventbridge-codebuild-sns

Deploy

cd cdkcdk deploy


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:

Guyu Ye

Guyu Ye

Guyu is a Sustainability App Architect at AWS Professional Services.