Home > Net >  Can use environment variables with the sub intrinsic function?
Can use environment variables with the sub intrinsic function?

Time:11-02

I am using the sub function to define a resource within an aws IAM service.

Resource:
  - !Sub 'arn:aws:s3:::example-${TEST1}-${AWS::REGION}-test'

${TEST1}: it is an environment variable that I have in my java project.

${AWS::REGION}: pseudo parameter

I want to know if !sub is able to read the environment variable and if it can't, is there any way I can do it even if it's not with this function

CodePudding user response:

No, you cannot reference environment variables within cloudformation.

You'll have to wrap the cloudformation deployment with a script that parses the environment variables and feeds them in as parameters, which can then be referenced in the template.

CodePudding user response:

Make the environment variable a CloudFormation Parameter and set the value. Then !Sub will work as expected. You can create a parameter file if you need to massage the values with sed or jq.

  • Related