amazon-web-services - 角色不能由 events.amazonaws.com 承担

标签 amazon-web-services amazon-iam amazon-cloudwatch

我正在尝试使用代码放置 cloudwatch 事件规则:

await cloudwatchevents.putRule({
  Name: 'xxx-ec2-start',
  EventPattern: '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["running"]}}',
  State: 'ENABLED',
  RoleArn: `arn:aws:iam::${account.Id}:role/skynet-cloudwatch-eventbus`,
}).promise()

但是,我得到:

(节点:29939)未处理的PromiseRejectionWarning:ValidationException:主体“events.amazonaws.com”不能承担提供的角色“arn:aws:iam::00000000000:role/xxx-cloudwatch-eventbus”。

该角色已经具有允许的假定策略文档 events.amazonaws.com .为什么还是失败?

enter image description here

最佳答案

您收到此错误的原因是“events.amazonaws.com”未列为角色 theRole 的可信实体。(在您的情况下为 skynet-cloudwatch-eventbus)

解决此问题的一种方法是转到 https://console.aws.amazon.com/iam/home?region=us-east-1#roles/theRole (将此链接调整为您所在的地区 + 真实角色名称)> 信任关系选项卡 > 编辑信任关系按钮 > 粘贴在服务下的“events.amazonaws.com”,如下面的示例所示。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "lambda.amazonaws.com",
          "apigateway.amazonaws.com",
          "events.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]

关于amazon-web-services - 角色不能由 events.amazonaws.com 承担,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59479734/

相关文章:

python - 运行时警告 : Parent module 'src' not found while handling absolute import - AWS Lambda

amazon-web-services - 开发机器上的 EC2 实例元数据

amazon-web-services - 如何调试cloudformation模板?策略中的语法错误。 YAML 文件

amazon-web-services - AWS 云观察 : how to fetch custom metrics from AWS Elastic Beanstalk

amazon-web-services - 为什么我的Elastic Beanstalk应用程序尽管具有角色,但仍然拒绝PutItem访问我的DynamoDB?

amazon-web-services - 结合 AWS CLI 和 CloudFormation?

amazon-web-services - 我可以在 S3 存储桶策略中使用 Cognito 用户池组吗?

python - 如何(正确地)在 AWS Lambda 函数中使用外部凭证?

amazon-web-services - aws.events 的 EventBridge 规则问题

mysql - 对发生故障的从属 AWS 服务器使用什么指标