aws cloudformation 错误:无法解压缩上传的文件.请检查您的文件,然后再次尝试上传 [英] aws cloudformation error: Could not unzip uploaded file. Please check your file, then try to upload again
问题描述
使用 aws cloudformation 命令 package
和 deploy
我试图将我的本地 lambda 函数复制到 s3 并部署模板.但是我在部署堆栈时遇到了一个问题.出现错误:无法解压缩上传的文件.请检查您的文件,然后再次尝试上传.(服务:AWSLambdaInternal;状态代码:400
Using aws cloudformation commands package
and deploy
I'm trying to copy my local lambda function to s3 and deploy template.
But I have faced with a problem during deploying a stack.
An error occur:
Could not unzip uploaded file. Please check your file, then try to upload again. (Service: AWSLambdaInternal; Status Code: 400
问题:当我手动压缩 labmda 函数并将其复制到 s3 时 - 它可以工作.我的工作流程或模板有什么问题?
Question: When I zip the labmda function manually and copy it to s3 - it works. What wrong in my workflow or my template?
我的代码结构:
./template/template.yaml
./template/lambda.py
命令:
aws cloudformation package \
--template-file ./template.yaml \
--output-template-file ./output-template2.yaml \
--s3-bucket "vmv-template-2"
aws cloudformation deploy \
--template-file ./output-template2.yaml \
--stack-name audi2 \
--capabilities CAPABILITY_IAM
我的模板文件
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
lambdaFunctionName:
Type: "String"
AllowedPattern: "^[a-zA-Z0-9]+[a-zA-Z0-9-]+[a-zA-Z0-9]+$"
Default: "createS3Object"
Resources:
LambdaCreateS3Object:
Type: 'AWS::Lambda::Function'
Properties:
Description: Create s3 object and write content from request body
FunctionName: !Ref "lambdaFunctionName"
Code: ./lambda.py
Timeout: 60
Handler: lambda.lambda_handler
Runtime: python3.7
MemorySize: 128
Role: !GetAtt LambdaExecutionRole.Arn
LambdaExecutionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "sts:AssumeRole"
Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Policies:
- PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Effect: "Allow"
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${lambdaFunctionName}:*"
PolicyName: "lambda"
- PolicyName: getAndDeleteObjects
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 's3:GetObject'
- 's3:DeleteObject'
- 's3:PutObject'
Resource: arn:aws:s3:::*
lambdaLogGroup:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName: !Sub "/aws/lambda/${lambdaFunctionName}"
RetentionInDays: 90
推荐答案
基于评论.
我试图验证报告的问题.发现的是 package
命令的一个相当有趣的行为.
I tried to verify the issue reported. What was found, was a rather intresting behavior of the package
command.
即当package
命令以如下方式执行时(template
文件夹的外部):
Namely, when the package
command is executed in the following way (outside of template
folder):
aws cloudformation package \
--template-file ./template/template.yaml \
--output-template-file ./output-template2.yaml \
--s3-bucket "vmv-template-2"
上传到 S3 的对象只是一个重命名的 template.yaml
文件.然后 deploy
命令失败,因为报告需要一个 ZIP 文件.
The uploaded object to S3 will be just a renamed template.yaml
file. Then the deploy
command fails as reported expecting a ZIP file.
但是,当 package
命令在 inside template
文件夹中执行时,它会按预期工作,在 S3 中生成一个 ZIP:>
However, when the package
command is executed inside template
folder, then it works as expected, producing a ZIP in S3:
aws cloudformation package \
--template-file ./template.yaml \
--output-template-file ./output-template2.yaml \
--s3-bucket "vmv-template-2"
之后,deploy
命令成功.
这篇关于aws cloudformation 错误:无法解压缩上传的文件.请检查您的文件,然后再次尝试上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!