Skip to content

Instantly share code, notes, and snippets.

@kyptov
Created April 20, 2021 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyptov/c822113a10d02bc9d29f9cef163ae3d7 to your computer and use it in GitHub Desktop.
Save kyptov/c822113a10d02bc9d29f9cef163ae3d7 to your computer and use it in GitHub Desktop.
Run lambda every 5 minutes
AWSTemplateFormatVersion: "2010-09-09"
Resources:
LambdaFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Path: /service-role/
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
#language=JavaScript
ZipFile: |
exports.handler = async function (event) {
console.log(event)
return "Success";
};
Handler: index.handler
Role: !GetAtt LambdaFunctionRole.Arn
Runtime: nodejs12.x
PeriodicJobRule:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: "cron(*/5 * * * ? *)"
State: ENABLED
Targets:
- Id: LambdaFunction
Arn: !GetAtt LambdaFunction.Arn
PermissionToInvokeCreateLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunction
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt PeriodicJobRule.Arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment