AWS' Serverless Application Model 还是……非常新。由于缺乏任何有关使用 CLI 部署应用程序所需的 IAM 权限的文档,我制定了这项似乎可行的策略,并且只有 grants the least needed permissions 用于该任务。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"lambda:UpdateFunctionCode",
"s3:PutObject",
"cloudformation:DescribeStackEvents",
"cloudformation:UpdateStack",
"cloudformation:DescribeStackResource",
"cloudformation:CreateChangeSet",
"cloudformation:DescribeChangeSet",
"cloudformation:ExecuteChangeSet",
"cloudformation:GetTemplateSummary",
"cloudformation:ListChangeSets",
"cloudformation:DescribeStacks"
],
"Resource": [
"arn:aws:lambda:*:123456789012:function:*-SAM-*",
"arn:aws:cloudformation:*:123456789012:stack/<STACK NAME OR GLOB>/*",
"arn:aws:cloudformation:<AWS_REGION>:aws:transform/Serverless-2016-10-31",
"arn:aws:s3:::aws-sam-cli-managed-default-samclisourcebucket-*/*"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucketMultipartUploads"
],
"Resource": "arn:aws:s3:::aws-sam-cli-managed-default-samclisourcebucket-*"
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "cloudformation:ValidateTemplate",
"Resource": "*"
}
]
}
注意:
将<STACK NAME OR GLOB> 替换为最适合您需求的内容,例如:
-
* 如果您不在乎这授予访问哪个 CloudFormation 堆栈
-
*-SAM-* 如果您以某种一致性命名您的 SAM CloudFormation 应用程序
将<AWS_REGION> 替换为您所在的地区。
arn:aws:s3:::aws-sam-cli-managed-default-samclisourcebucket-* 是 SAM CLI 用于创建用于部署 CloudFormation 模板或更改集的存储桶的标准存储桶命名。您可以将其更改为明确为您创建的存储桶 SAM 的名称。