I'm in the processes of adding SAM templates to an existing serverless application. I have a no. of Lambdas which invoke other lambdas, and the invoker has policies that specify the ARN of the "invokee", or the invoked lambda. In this case, policy creation can be done once since my function name is static, e.g.:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-west-2:[acct-no]:function:MyLambda"
}
]
}
I can give the invoker a role with this policy without needing to changing it when I update the invokee. Under the SAM/CloudFormations framework however, the created function is automatically appended a string to its name, (e.g. arn:aws:lambda:us-west-2:[acct-no]:function:MyLambda-3kx71lzkhge3
) which nullifies previously created policies as the old ARN is no longer valid, which makes me think I need to create the policy ARN dynamically.
I'm not sure what the correct way to do this is. My understanding is that the ARN is an output of sam deploy
, so currently, I have in mind first deploying the invokee, noting the ARN, then updating the sam template of the invoker with the ARN, and then deploying the invoker. This however feels incorrect as it is a manual intervention of a process designed to be automated. I was wondering if there's another way to go about this, and would appreciate any insight anyone could lend.