Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic AWS Sam Schedule Event Input param

We are automating a lambda via SAM to run on a Schedule Event. We use YAML but we are unable to work out how to use !Sub to make the Input be dynamic.

If you read the sam documentation it says that Input needs to be a JSON formatted string

The following code works for us:

Events:
    Event1:
      Type: Schedule
      Properties:
        Schedule: rate(1 minute)
        Input: >-
          {
            "sqsUrl": "https://sqs.12344.url",
            "snsArn": "arn:val"
          }

But we need to insert dynamic params into the Input like so:

Events:
    Event1:
      Type: Schedule
      Properties:
        Schedule: rate(1 minute)
        Input: >-
          {
            "sqsUrl": "https://sqs.${AWS::AccountId}.url",
            "snsArn": "arn:val"
          }

We have tried to do this in multiple ways, using a !Sub but the deployment always fails saying that it needs to be valid JSON.

What is the correct way to make this JSON string use variables?

Thanks, Mark

like image 726
newbreedofgeek Avatar asked Oct 20 '25 14:10

newbreedofgeek


1 Answers

So, you should wrap all Input value (in your case this is json-string and of course it should be wrapped with some quotes) with the !Sub function.

Then, it will look like:

Input:
  Fn::Sub: '{"sqsUrl": "https://sqs.${AWS::AccountId}.url","snsArn": "arn:val"}'
like image 134
Aleksey Balenko Avatar answered Oct 22 '25 04:10

Aleksey Balenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!