是否可以根据CloudFormation模板中的正则表达式模式验证环境变量?
有点像这样,但是 AllowedPattern 实际上不能这样使用。
AllowedPattern
Conditions: IsValidVersion: !AllowedPattern [!Sub ${APP_VERSION}, "rel-\\d{4,8}" ]
CloudFormation模板在AWS服务端执行,它们无法访问任何环境变量。您可以做的是指定参数并为其分配允许的模式:
Parameters: AppVersion: Type: "String" AllowedPattern: "rel-\\d{4,8}"
并执行CLI命令传递环境变量:
aws cloudformation deploy \ --stack-name your-stack \ --template-file your-template \ --parameter-overrides AppVersion=${APP_VERSION}