【发布时间】:2019-06-01 14:22:07
【问题描述】:
我没有完全掌握使用 sam 发布/部署的流程。我最大的问题是我的 sam 模板声明了一个 AWS::Serverless::Function 并且 CodeUri 参数强制我放入一个 s3 存储桶 url。
我见过一些示例,其中 CodeUri 只是您计算机上代码资源的路径。当我尝试这个山姆抱怨
'CodeUri' 不是带有可选 versionId 查询参数的“s3://bucket/key”形式的有效 S3 Uri。
要解决这个问题,我必须
- 将函数的 CodeUri 更改为模板中代码的根文件夹
- 进入AWS控制台,删除我s3存储桶中的资源,否则sam包不会上传
- 运行 sam 包上传我更新的代码资源
- 复制新的 s3 资源密钥
- 回到我的模板,用新的 s3 存储桶 uri 替换 CodeUri
- 运行山姆部署
这真是令人讨厌。
我错过了什么?
{
"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"]
}
}
}
}
【问题讨论】:
标签: aws-lambda aws-serverless aws-sam-cli