Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda scheduled event source via cloudformation

I already have my lambda / roles defined in cloudformation and would love to also use it to add a scheduled eventsources ... are there any docs or examples around ?

like image 857
grosser Avatar asked Dec 18 '15 18:12

grosser


People also ask

Can CloudFormation trigger Lambda?

AWS CloudFormation invokes your Lambda function asynchronously with an event that includes a callback URL. The function is responsible for returning a response to the callback URL that indicates success or failure. For the full response syntax, see Custom resource response objects.

Can CloudFormation interact with Lambda?

All in all, CloudFormation makes deploying AWS Lambda functions incredibly simple. Start by creating the template file that will define your resources. This will be your working folder for your code. Next, create your function in the appropriate file for your desired Lambda runtime.


1 Answers

Use Aws::Event::Rule with a ScheduleExpression and a AWS::Lambda::Permission

// rule to periodically call the lambda "TagWatcherRule": {   "Type": "AWS::Events::Rule",   "Properties": {     "ScheduleExpression": "rate(10 minutes)",     "Targets": [       {         "Id": "TagWatcherScheduler",         "Arn": {           "Fn::GetAtt": [             "TagWatcherFunction",             "Arn"           ]         }       }     ]   } }, // role may call the lambda "InvokeLambdaPermission": {   "Type": "AWS::Lambda::Permission",   "Properties": {     "FunctionName": {       "Fn::GetAtt": [         "TagWatcherFunction",         "Arn"       ]     },     "Action": "lambda:InvokeFunction",     "Principal": "events.amazonaws.com",     "SourceArn": {       "Fn::GetAtt": [         "TagWatcherRule",         "Arn"       ]     }   } } 
like image 110
grosser Avatar answered Oct 02 '22 22:10

grosser