3

Here is a SAM template (same as a CloudFormation template):

Globals:
    Function:
        Environment:
            Variables:
                BAR: '{{resolve:ssm:myparam:1}}'
...
    MyParam:
        Type: "AWS::SSM::Parameter"
        Properties:
            Name: myparam
            Type: String
            Value: 'REPLACE_ME' # must be defined manually in the AWS Console

I cannot deploy this stack because:

FAILED. Reason: Parameters: [ssm:myparam:1] cannot be found.

Of course, I am creating this parameter in the stack…


How can I reference a SSM parameter I am creating in the same template?

Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
  • I think it makes no sense to use the same template for SSM parameters, because you can access them via !GetAtt (see below). – Sandro Keil Mar 21 '19 at 19:50

1 Answers1

2

Have you tried to access the variable via Fn::GetAtt (!GetAtt MyParam.Value)?

Globals:
    Function:
        Environment:
            Variables:
                BAR: !GetAtt MyParam.Value
...
    MyParam:
        Type: "AWS::SSM::Parameter"
        Properties:
            Name: myparam
            Type: String
            Value: 'REPLACE_ME' # must be defined manually in the AWS Console
Sandro Keil
  • 1,407
  • 1
  • 8
  • 5
  • Thank you, the thing is that I want to store secret keys in the parameter (and so I don't want to write that secret in the template). So I use CloudFormation to create the parameter, but then I have to manually define the value in the AWS Console. So I really want to reference the value of the parameter, not the initial value I put in the template. – Matthieu Napoli Mar 22 '19 at 08:07
  • Matthieu, You may be able to do this with SSM Parameters, but at my job we're doing something similar using SecretsManager Secrets. We're passing a !Ref YourSecretName as a Lambda function Environment Variable in CF. When the function is created the Env Variable is an ARN reference, which can then be resolved at run time. Would that work for your situation? – Amos Long Feb 15 '21 at 18:26