amazon-web-services - 如何在 Cloudformation 模板条件中使用 AWS SSM 参数存储值?
问题描述
我已在 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-value
和ssm_value_is_correct
= no
。
为什么条件语句解析为“否”而不是“是”?在条件句中使用 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
推荐阅读
- html - 创建响应式标题时无法正确定位图像
- mongodb - MongoDB 是否支持对聚合查询的结果进行聚合查询?
- firebase - Vuex 处理附加类的最佳实践:导入视图还是仅在商店中?
- python - 如果键存在,则追加到字典中的值/将值转换为列表然后追加
- java - 使用java的Cesar密码解密
- vue.js - 使用 Nuxt.js 时动态 Vuex 模块初始化的最佳方法是什么?
- python - 有人如何将数据从 MetaTrader 4/5 终端发送到外部服务器?
- r - SAS无法打开使用“haven”从R导出的文件
- python - 成对交换(Python、Pandas、NumPy)
- c++ - condition_variable.notify 是同步点吗?