7
votes

I have configured a key value pair in the AWS SSM parameter store UI as my-ssm-key = ssm-value.

I have the following YAML template for CF built on Serverless:

service: redirect-test

provider:
  name: aws
  runtime: python3.8

  environment:
    ssm_value: '{{resolve:ssm:my-ssm-key:1}}'
    ssm_value_is_correct: !If [SSM_KEY_IS_CORRECT, yes, no]

functions:
  hello:
    handler: handler.hello

resources:
  Conditions:
    SSM_KEY_IS_CORRECT:
      !Equals
        - '{{resolve:ssm:my-ssm-key:1}}'
        - 'ssm-value'

On deploying the stack, environment variables are being set to ssm_value = ssm-value and ssm_value_is_correct = no.

Why is the conditional statement resolving to "no" instead of "yes"? What is the correct way to use SSM parameter store values in conditionals?

Param store screenshot: SSM param store screenshot Env variables screenshot: Env variables screenshot

1
why dont you also set SSM_KEY_IS_CORRECT as an environment variable, so you can see how is it resolving ?Arun K
@ArunK I've tried doing foo: SSM_KEY_IS_CORRECT but in that case SSM_KEY_IS_CORRECT is just treated as a string and not a variable. So the environment variable is just "SSM_KEY_IS_CORRECT".rohithpr

1 Answers

1
votes

I was able to resolve the issue by using this CF template:

service: redirect-test

provider:
  name: aws
  runtime: python3.8

  environment:
    ssm_value: !Ref MySSMValue
    ssm_value_is_correct: !If [SSM_KEY_IS_CORRECT, yes, no]

functions:
  hello:
    handler: handler.hello

resources:
  Conditions:
    SSM_KEY_IS_CORRECT:
      !Equals
        - !Ref MySSMValue
        - ssm-value

  Parameters:
    MySSMValue:
      Description: My SSM Value
      Type: AWS::SSM::Parameter::Value<String>
      Default: my-ssm-key

Environment variables with correct expected values