如何在 Cloudformation 模板条件中使用 AWS SSM 参数存储值?

How to use AWS SSM parameter store values in Cloudformation template conditionals?

我在 AWS SSM 参数存储 UI 中配置了一个键值对作为 my-ssm-key = ssm-value.

我有以下基于无服务器构建的 CF 的 YAML 模板:

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'

在部署堆栈时,环境变量被设置为 ssm_value = ssm-valuessm_value_is_correct = no.

为什么条件语句解析为 "no" 而不是 "yes"?在条件中使用 SSM 参数存储值的正确方法是什么?

参数存储截图: 环境变量截图:

我使用这个 CF 模板解决了这个问题:

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