Skip to content

Instantly share code, notes, and snippets.

@marcelog
Created February 26, 2017 16:57
Show Gist options
  • Save marcelog/a4c92062ac8e6eddd8aec02bde5f032c to your computer and use it in GitHub Desktop.
Save marcelog/a4c92062ac8e6eddd8aec02bde5f032c to your computer and use it in GitHub Desktop.
An example of defining a CloudWatch scheduled event as an event for an AWS Lambda in the serverless framework by using a CloudFront template for resources
functions:
MyLambdaFunction:
role: MyLambdaRole
handler: index.handle
resources:
Resources:
MyEventName:
Type: AWS::Events::Rule
Properties:
Description: An awesome periodic event
Name: MyEventName
ScheduleExpression: "cron(0 6 * * ? *)"
State: ENABLED
RoleArn:
Fn::GetAtt:
- "MyLambdaRole"
- "Arn"
Targets:
-
Arn:
Fn::GetAtt:
- "MyLambdaFunction"
- "Arn"
Id: "MyLambdaFunction"
Input: '{"key": "value"}'
MyLambdaRole:
Type: AWS::IAM::Role
Properties:
Path: /my_uservices/
RoleName: MyLambdaRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- events.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: MyLambdaPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "arn:aws:logs:*:*:log-group:/aws/lambda/*:*:*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment