Created
April 20, 2021 09:45
-
-
Save kyptov/c822113a10d02bc9d29f9cef163ae3d7 to your computer and use it in GitHub Desktop.
Run lambda every 5 minutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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