【发布时间】:2021-05-19 18:07:39
【问题描述】:
使用 terraform 测试 AWS 实例调度程序。代码here
看起来我的代码出现了这个错误:
错误:等待创建 CloudFormation 堆栈时出错:未能创建 CloudFormation 堆栈,请求回滚 (ROLLBACK_COMPLETE):[“未能创建以下资源:[主要]。用户请求回滚。” “您的访问已被 S3 拒绝,请确保您的请求凭据对解决方案-us-gov-west-1/aws-instance-scheduler/v1.3.1/instance-scheduler.zip 的 GetObject 具有权限。S3 错误代码: AccessDenied.S3 错误消息:访问被拒绝(服务:AWSLambdaInternal;状态代码:403;错误代码:AccessDeniedException;请求 ID:731b7c0d-cda9-4f9e-b821-efed4cbced46;代理:null)"]
下面是部分代码:IAM policy
"InstanceSchedulerEncryptionKeyAlias": {
"Type": "AWS::KMS::Alias",
"Properties": {
"AliasName": "alias/instance-scheduler-encryption-key",
"TargetKeyId": {
"Ref": "InstanceSchedulerEncryptionKey"
}
}
},
"SchedulerPolicy": {
"Type": "AWS::IAM::Policy",
"Metadata": {
"cfn_nag": {
"rules_to_suppress": [
{
"id": "W12",
"reason": "All policies have been scoped to be as restrictive as possible. This solution needs to access ec2/rds resources across all regions."
}
]
}
},
"Properties": {
"PolicyName": "SchedulerPolicy",
"Roles": [
{
"Ref": "SchedulerRole"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutRetentionPolicy",
"logs:*"
],
"Resource": [
{
"Fn::Join": [
":",
[
"arn:aws-us-gov:logs:*:*:*",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"log-group",
{
"Ref": "SchedulerLogGroup"
},
"*"
]
]
},
{
"Fn::Join": [
":",
[
"arn:aws-us-gov:logs:*:*:*",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"log-group:/aws/lambda/*"
]
]
}
]
},
{ "Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws-us-gov:s3:::*"
]
},
IAM 角色
"SchedulerRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Path": "/"
}
},
我确定我的代码格式不正常,或者我在 s3 的角色或政策中遗漏了某些内容。在这里查找类似的问题,并将感谢任何关于我的代码的指针。我知道我很接近。
【问题讨论】:
标签: amazon-web-services aws-lambda terraform amazon-iam