我无法通过sam发布/部署完全掌握流程。我最大的麻烦是我的sam模板声明了AWS::Serverless::Function
,而CodeUri参数则迫使我输入s3存储桶url。
我看过一些示例,其中CodeUri只是计算机上代码资源的路径。当我尝试此sam抱怨
“ CodeUri”不是带有可选versionId查询参数的形式为“ s3:// bucket / key”的有效S3 Uri。
要解决这个问题,我必须
这是令人讨厌的。
我想念什么?
{
"Description" : "Serverless backend",
"Transform" : "AWS::Serverless-2016-10-31",
"Globals" : {
},
"Resources" : {
"db" : {
"Type": "AWS::RDS::DBInstance",
"Properties" : {
"AllocatedStorage": "20",
"DBInstanceClass": "db.t2.micro",
"DBName": "nameforthedb",
"DeleteAutomatedBackups": true,
"Engine": "postgres",
"MasterUsername": "masterUserName",
"MasterUserPassword": "******",
"PubliclyAccessible": true
}
},
"signIn" : {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.signIn",
"Runtime": "nodejs8.10",
"CodeUri": "src", <--- complains when this is set to this. Code lives in the src folder. this is fine when I run sam package, but has to be changed to the s3 bucket when running sam deploy
"FunctionName": "signIn",
"Events": {
"SignIn" : {
"Type": "Api",
"Properties" : {
"Path" : "/signIn",
"Method" : "post"
}
}
}
}
},
"Auth" : {
"Type" : "AWS::Cognito::UserPool",
"Properties": {
"Schema" : [
{
"AttributeDataType": "String",
"Name": "email",
"Mutable": true,
"Required": true
},
{
"AttributeDataType": "String",
"Name": "family_name",
"Mutable": true,
"Required": true
},
{
"AttributeDataType": "String",
"Name": "given_name",
"Mutable": true,
"Required": true
},
{
"AttributeDataType": "String",
"Name": "houseId",
"Mutable": true
},
{
"AttributeDataType": "Boolean",
"Name": "owner",
"Mutable": true
}
],
"UsernameAttributes": ["email"]
}
}
}
}
答案 0 :(得分:1)
TemporaryFix的评论是正确的答案。 AWS SAM正确将工件上传到s3,然后生成更新的模板文件。您需要在运行--template-output-path packaged.yaml
时指定sam package
,然后此命令将生成引用该函数的s3存储桶的文件。然后,在运行--template-file packaged.yaml
deploy command
类似:
sam build
sam package --s3-bucket your-bucket --output-template-file packaged.yaml
sam deploy --template-file packaged.yaml \
--region eu-west-1 \
--capabilities CAPABILITY_IAM \
--stack-name your-stack
答案 1 :(得分:0)
您可以使用此工作流程来部署lambda函数
生成一个随机数。 (类似于java uuid),也可能是您的git commit号
将工件上传到s3:// your_lmabda_code_bucket_name / uuid
在您的sam中,将codeuri配置为
CodeUri:
Bucket: your_lmabda_code_bucket_name
Key: !Sub '${uuid}/main.zip'
在部署时将uri作为参数传递。