CloudFormation CLI package命令模板路径无效问题求助
解决CloudFormation package命令无法读取S3/HTTPS路径模板的问题
问题原因
aws cloudformation package命令的--template-file参数仅支持本地文件路径,不直接接受S3 URI或HTTPS URL作为输入,这是报错的核心原因。另外你命令中--s3-bucket参数填了桶ARN,该参数实际需要的是桶名称,这也会引发异常。
解决步骤
将S3上的模板下载到CloudShell本地
用aws s3 cp命令把模板文件拉到当前会话的临时存储中:aws s3 cp s3://<my bucket name>/macros/macro.yaml ./macro.yaml使用本地路径执行package命令
替换为本地模板路径,并修正--s3-bucket参数为桶名称:aws cloudformation package --template-file ./macro.yaml --s3-bucket <my bucket name> --output-template-file packaged.yaml(可选)将打包后的模板上传回S3
如果需要持久化打包后的模板,再上传到S3:aws s3 cp ./packaged.yaml s3://<my bucket name>/macros/packaged.yaml
注意事项
- CloudShell的本地存储是临时的,会话结束后文件会被清除,所有操作需在同一会话内完成
- 确保当前CloudShell使用的IAM角色具备该S3桶的
s3:GetObject(下载模板)和s3:PutObject(上传打包后模板、Lambda代码)权限 - 你的宏模板中
CodeUri已经指向S3路径,package命令会直接复用该路径,无需额外处理Lambda代码
原模板及命令日志
宏模板(macro.yaml)
Transform: AWS::Serverless-2016-10-31 Resources: MacroFunction: Type: AWS::Serverless::Function Properties: Runtime: python3.7 PackageType: Zip CodeUri: s3://<my bucket name>/macros/lambda/ Handler: explode.handler Macro: Type: AWS::CloudFormation::Macro Properties: Name: Explode FunctionName: Fn::GetAtt: MacroFunction.Arn
报错命令日志
$ aws cloudformation package --template-file s3://<my bucket name>/macros/macro.yaml --s3-bucket <my bucket arn> --output-template-file packaged.yaml Invalid template path s3://********************/macros/macro.yaml $ aws cloudformation package --template-file https://<mybucketname.s3.amazonaws.com/macros/macro.yaml --s3-bucket <my bucket arn> --output-template-file packaged.yaml Invalid template path https://*************.s3.amazonaws.com/macros/macro.yaml
内容的提问来源于stack exchange,提问作者humbleStrength
相关产品推荐
相关产品推荐

