1

Cloudformation command:

- aws cloudformation create-stack --stack-name stackName --template-body file://cloudformation.yaml --parameters ParameterKey=keyName,ParameterValue=myKeys

I need to paste env variable into UserData cloudformation sctipt. So at the end it would have docker pull quay.io/apple/myRepo:myVarName

UserData:
      Fn::Base64: !Sub |
        docker pull quay.io/apple/myRepo:master
4
  • !Join [ ":", ["quay.io/apple/myRepo", !Ref myParameterName ] ] Commented Jun 29, 2020 at 20:32
  • I see. But how to you actually pass it i? Can you share example? Commented Jun 29, 2020 at 20:42
  • Your post already includes an example of passing parameter values through the CLI Commented Jun 29, 2020 at 20:58
  • Those names used in cf file too ofter and it sort of confusion. I would appreciate simple example Commented Jun 29, 2020 at 20:59

1 Answer 1

1

If you executed aws cloudformation create-stack with the following parameters:

--parameters ParameterKey=keyName,ParameterValue=myKeys

in your template you need to have Parameters section:

Parameters:

  keyName:
    Type: String

Then in your UserData you would reference parameter keyName as follows:

UserData:
  Fn::Base64: !Sub |
     param_value=${keyName}
Sign up to request clarification or add additional context in comments.

7 Comments

Would it look like this if you would have to concatenate it? docker pull quay.io/repo/apple:${branchName}
@Sergio13 What do you mean that it does not work? Any error messages? What do your updated UserData and Parameters sections look like now?
No error messages, it stops execution at that line, and if I navigate to ec2 instance I have no access to that branchName var.
My code: Parameters: keyName: Description: Name of an existing EC2 KeyPair to enable SSH access to the EC2 Instances Type: "AWS::EC2::KeyPair::KeyName" branchName: Type: String Resources: launchTemplate: Properties: LaunchTemplateData: UserData: Fn::Base64: !Sub | #!/bin/bash -xe docker pull quay.io/****/****:${branchName}
You answer actually worked. The issue was with codefresh way to pass data into cf script. It just needed to be assigned into var before passing it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.