How to Deploy a Scheduled EventBridge Lambda With GitHub Actions
Update the function code, create or update an EventBridge schedule rule, and target the function with the right invoke permission.
After deploying code, define a schedule with aws events put-rule --schedule-expression, allow EventBridge to invoke the function with aws lambda add-permission, then attach the function as a target via put-targets.
Steps
- Update the Lambda function code.
- Create the rule with
aws events put-rule --schedule-expression. - Grant invoke permission with
aws lambda add-permission(idempotent statement id). - Attach the function with
aws events put-targets.
Workflow
.github/workflows/deploy.yml
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: zip -r function.zip index.js
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-sched-deploy
aws-region: us-east-1
- run: |
aws lambda update-function-code \
--function-name nightly-job --zip-file fileb://function.zip
aws events put-rule --name nightly \
--schedule-expression 'cron(0 3 * * ? *)'
aws lambda add-permission --function-name nightly-job \
--statement-id nightly-evt --action lambda:InvokeFunction \
--principal events.amazonaws.com \
--source-arn arn:aws:events:us-east-1:123456789012:rule/nightly || true
aws events put-targets --rule nightly \
--targets 'Id=1,Arn=arn:aws:lambda:us-east-1:123456789012:function:nightly-job'Gotchas
- EventBridge cron uses a 6-field expression with a
?in either day field, not standard 5-field cron. add-permissionfails if the statement id already exists; the|| truekeeps re-runs idempotent.
Related guides
How to Deploy a Zip Lambda Function With GitHub ActionsPackage and deploy an AWS Lambda function as a zip from GitHub Actions using OIDC and aws lambda update-funct…
How to Deploy a Step Functions State Machine With GitHub ActionsUpdate an AWS Step Functions state machine definition from GitHub Actions with aws stepfunctions update-state…