amazon-web-services - Terraform-Cloudformation-aws 实例提供程序 : Provided Arn is not in correct format

标签 amazon-web-services aws-lambda terraform aws-cloudformation amazon-cloudwatch

我正在创建一个 cloudformation 堆栈,以通过 TF 在 aws gov 云中生成 aws 实例调度程序。目标是根据标签启动/停止 ec2。有很多方法可以实现它,但我必须使用 terraform 和 cloudformation。这是仓库 --> https://github.com/Vinod1908/TestTerraform/blob/master/instanceScheduler.tf
以下是我认为被阻止的代码部分:

        "InstanceSchedulerEncryptionKey": {
            "Type": "AWS::KMS::Key",
            "Properties": {
                "Description": "Key for SNS",
                "Enabled": true,
                "EnableKeyRotation": true,
                "KeyPolicy": {
                    "Statement": [
                        {
                            "Sid": "default",
                            "Effect": "Allow",
                            "Principal": {
                               "AWS": { 
                                    "Fn::Sub": "arn:$${AWS::Partition}:iam::$${AWS::AccountId}:root"    
                                }
                            },
                            "Action": "kms:*",
                            "Resource": "*"
                        },
                        {
                            "Sid": "Allows use of key",
                            "Effect": "Allow",
                            "Principal": {
                                "AWS": {
                                    "Fn::GetAtt": [
                                        "SchedulerRole",
                                        "Arn"
                                    ]
                                }
                            },
                            "Action": [
                                "kms:GenerateDataKey*",
                                "kms:Decrypt"
                            ],
                            "Resource": "*"
                        }
                    ]
                }
            }
        },

              "Code": {
                    "S3Bucket": {
                        "Fn::Join": [
                            "-",
                            [
                                "solutions",
                                {
                                    "Ref": "AWS::Region"
                                }
                            ]
                        ]
                    },
                    "S3Key": "aws-instance-scheduler/v1.3.1/instance-scheduler.zip"

错误:

Error: error waiting for CloudFormation Stack creation: failed to create CloudFormation stack, rollback requested (ROLLBACK_COMPLETE): ["The following resource(s) failed to create: [InstanceSchedulerEncryptionKey, SchedulerRule]. Rollback requested by user." "Resource creation cancelled" "Parameter arn:aws:lambda:us-gov-west-1:###########..:function:Schedule-InstanceSchedulerMain is not valid. Reason: Provided Arn is not in correct format. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 37adac0c-6758-4b4f-ac86-0d0140742c80; Proxy: null)"]

不确定它在政府云中是否可行,但我正在寻找潜在的解决方案并发现了这个 https://github.com/awslabs/aws-instance-scheduler/issues/11 。我正在测试它,但尚未成功..请帮助!!

添加新行:

谢谢大家的回复。我的问题是使用正确的 arn arn:aws-us-gov 我只需应用该代码即可完成。现在我在下面看到了这个,我确信它与我的 s3 上的策略/角色有关。请让我知道下面的代码有什么问题。有什么想法吗?

s3代码部分:

      "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"
                            ],
                            "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:GetObject",
                                "s3:PutObject",
                                "s3:*"
                            ],
                            "Resource": {
                                "Fn::Join": [
                                    ":",
                                    [
                                        "arn:aws-us-gov:s3:::instanceschedulertest",
                                        "arn:aws-us-gov:s3:::instanceschedulertest/*"
                                    ]
                                ]
                            }
                        },                        
                        {
                            "Effect": "Allow",
                            "Action": [
                                "rds:DeleteDBSnapshot",
                                "rds:DescribeDBSnapshots",
                                "rds:StopDBInstance"
                            ],
                            "Resource": {
                                "Fn::Join": [
                                    ":",
                                    [
                                        "arn:aws-us-gov:rds:*",
                                        {
                                            "Ref": "AWS::AccountId"
                                        },
                                        "snapshot:*"
                                    ]
                                ]
                            }
                        },
                        {
                            "Effect": "Allow",
                            "Action": [
                                "rds:AddTagsToResource",
                                "rds:RemoveTagsFromResource",
                                "rds:DescribeDBSnapshots",
                                "rds:StartDBInstance",
                                "rds:StopDBInstance"

错误:

Error: error waiting for CloudFormation Stack creation: failed to create CloudFormation stack, rollback requested (ROLLBACK_COMPLETE): ["The following resource(s) failed to create: [Main]. Rollback requested by user." "Your access has been denied by S3, please make sure your request credentials have permission to GetObject for solutions-us-gov-west-1/aws-instance-scheduler/v1.3.1/instance-scheduler.zip. S3 Error Code: AccessDenied. S3 Error Message: Access Denied (Service: AWSLambdaInternal; Status Code: 403; Error Code: AccessDeniedException; Request ID: 95db6874-d4ad-4499-95f7-f73777a6d4db; Proxy: null)"]

谢谢大家的指点,我非常感谢你们的意见。

最佳答案

失败的原因是您在 Terraform 代码中形成了错误的 ARN。

在你的仓库中, link

将以下与 Lambda 相关的行:1047, 1358, 1420 替换为 "arn:aws-us-gov:lambda" 而不是 "arn:aws:lambda".

根据 aws 的文档:ARN 应采用以下格式 arn:aws-us-gov:lambda:account-id:function:function-name.

您的问题的答案是更新上述行。但我确信您会收到有关其他资源的错误,因为您创建的所有资源都位于美国区域。因此,请更新您在代码中形成的所有必要的 Joining Function Arn 行。 :)

关于amazon-web-services - Terraform-Cloudformation-aws 实例提供程序 : Provided Arn is not in correct format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66177516/

相关文章:

node.js - 使用 Nodejs Sharp 模块时出错。模块解析失败 : Unexpected character '' (1: 0)

通过 Terraform 在 Linux Docker 容器中设置 MySql

azure - 使用 terraform 为 Azure 应用程序网关添加重定向规则

python - 如何将Scrapy依赖打包为lambda?

azure - 使用 Terraform 将磁盘附加到多个虚拟机

amazon-web-services - Docker Elastic Beanstalk ELB忽略.ebextesnions

amazon-web-services - 列出某个区域或可用区中的所有 EC2 实例类型

django - 无法通过容器命令或 manage.py 在 aws beanstalk 中创建 django super 用户

swift - 如何在 Swift 中使用 Amazon SES 发送电子邮件?

amazon-web-services - 访问资源 https ://sqs. us-east-1.amazonaws.com/被拒绝