I want to build an ARN in my file dynamically, but I need to get my current AccountId. How can I access it as a variable?
For example:
example: arn:aws:states:${region}:${accountId}:stateMachine:${self:service}-${self:custom.stage}-example
What is the proper way to reference the current region
and accountId
?
This is now supported natively in Serverless Framework.
functions:
hello:
handler: my-function.handler
environment:
var: !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*:*:*'
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:*
Resource: !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${AWS::StackName}-*
See Pseudo Parameters Reference for the official docs.