Jophine
Jophine

Reputation: 594

SAM Template - Always enable event trigger for lambda

I have a lambda function created using SAM template which has an event trigger scheduled every 5 mins.

When the lambda get created for first time the event is enabled. But, when someone disables the trigger manually, the rerunning the stack does not enable it again.

Native cloud formation has an attribute called State in AWS::Events::Rule. But this is not supported in SAM Function's Events property. It is to be noted that this Events property gets translated to AWS::Events::Rule by SAM engine.

I tried adding the same State attribute in SAM but that doen't work.

Now the question is really how do I make sure Event is always enabled when SAM is used.

This there a hack available.

Sample code:

MyUpdater:
Type: 'AWS::Serverless::Function'
Properties:
  Handler: myupdater.lambda_handler
  Runtime: python3.6
  FunctionName: "myupdater"
  CodeUri: ./code
  Description: Sample updater lambda
  MemorySize: 128
  Timeout: 60
  Role: !ImportValue myIamRole
  KmsKeyArn: !ImportValue myKeyArn
  Events:
    Timer:
      Type: Schedule
      Properties:
        Schedule: rate(5 minutes)

Thanks in advance

Upvotes: 0

Views: 1057

Answers (2)

Gogu CelMare
Gogu CelMare

Reputation: 815

Add Enabled to properties:

Events:
    Timer:
      Type: Schedule
      Properties:
        Schedule: rate(5 minutes)
        Enabled: true 

Upvotes: 1

Sébastien Stormacq
Sébastien Stormacq

Reputation: 14905

This is not possible today. We are considering this feature (CFN properties pass-through) for the future.

Upvotes: 1

Related Questions