Reputation: 3616
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
Upvotes: 4
Views: 1921
Reputation: 1260
I've used something like:
!Sub |
{
"sqsUrl": "https://sqs.${AWS::AccountId}.url",
"snsArn": "arn:val"
}
the | (and >- among others) define the way yaml handles the line breaks in the string.
Upvotes: 0
Reputation: 862
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"}'
Upvotes: 2