CloudFormation YAML中ImportValue函数使用报错排查求助
CloudFormation中ImportValue未解析Environment变量的问题
你的代码里!ImportValue iml-authorizer-${Environment}中的${Environment}没被解析,核心原因是ImportValue函数本身不支持直接在参数里做变量插值,CloudFormation会把iml-authorizer-${Environment}当作完整的导出名称去查找,自然找不到对应的导出项。
解决方法
需要先用!Sub(或Fn::Sub)拼接出正确的导出名称,再传给!ImportValue,修正后的代码如下:
xxx: Type: "AWS::ApiGateway::Authorizer" DependsOn: - xxxxx Properties: AuthResultInSecs: "300" AuthUri: Fn::Sub: - "arn:aws:apigateway:xxx" - authLambdaArn: !ImportValue !Sub "iml-authorizer-${Environment}"
或者使用全函数写法:
authLambdaArn: Fn::ImportValue: Fn::Sub: "iml-authorizer-${Environment}"
额外排查点
- 确认
Environment是当前模板中定义的**参数(Parameters)或映射(Mappings)**项,且部署时传入了有效值 - 确认目标导出名称(比如
iml-authorizer-dev)已在同区域的其他CloudFormation栈中完成导出,名称完全匹配(CloudFormation导出名称大小写敏感) - 检查拼写:确认导出名称前缀、环境变量名没有拼写错误
- 修正资源类型拼写:
AWS::ApiGateWay::Authorizer应为AWS::ApiGateway::Authorizer(注意Gateway是连写格式)
内容的提问来源于stack exchange,提问作者Akshat Vyas
相关产品推荐
相关产品推荐

