【问题标题】:Serverless Framework The provided execution role does not have permissions to call SendMessage on SQSServerless Framework 提供的执行角色没有权限在 SQS 上调用 SendMessage
【发布时间】:2020-07-16 15:47:08
【问题描述】:

我正在尝试使用无服务器框架创建 AWS SQS 队列,
但我在部署 severless.yaml

时遇到以下错误
The provided execution role does not have permissions to call SendMessage on SQS

问题是 IAM 角色是由无服务器框架创建的,我无法控制框架向角色添加的权限,
理想情况下,如果函数触发器是 SQS,或者需要配置 DLQ,
我希望框架会为角色添加发送和接收消息权限,但我猜它没有

Serveless.yaml -

service: dlq

provider:
  name: aws
  runtime: nodejs12.x
  profile: csStage
  region: ap-southeast-1

plugins:
  - serverless-plugin-lambda-dead-letter

functions:
  dlqFunction:
    handler: handler.hello

    deadLetter:
      sqs: dl-queue

【问题讨论】:

    标签: amazon-web-services amazon-sqs serverless-framework


    【解决方案1】:

    您可以完全控制添加到该角色的权限。您可以在provider 下的 serverless.yml 文件中添加一个iamRoleStatements 部分,该部分描述了您希望应用于应用于函数的角色的权限。它看起来像:

    provider:
      iamRoleStatements:
        - Effect: Allow
          Action:
            - "sqs:SendMessage"
          Resource:
            - arn:aws:sqs:region:accountid:queueid
    
    

    您可以在此处的官方文档中找到更多信息:https://www.serverless.com/framework/docs/providers/aws/guide/iam/#iam/

    【讨论】:

      【解决方案2】:

      您可以使用 iamRoleStatements 将该权限授予您的 Lambda 函数。以下模板对我有用:

      service: dlq
      
      provider:
        name: aws
        runtime: nodejs12.x
        profile: csStage
        region: ap-southeast-1
      
        iamRoleStatements:
          - Effect: Allow
            Action:
              - sqs:SendMessage
            Resource: !GetAtt DLQ.Arn
      
      plugins:
        - serverless-plugin-lambda-dead-letter
      
      functions:
        dlqFunction:
          handler: handler.hello
      
          deadLetter:
            targetArn:
              GetResourceArn: DLQ
      
      resources:
          Resources:
            DLQ:
              Type: AWS::SQS::Queue
              Properties:
                QueueName: dl-queue
      

      【讨论】:

        猜你喜欢
        • 2019-08-23
        • 2017-05-01
        • 2020-03-01
        • 2020-05-30
        • 2020-03-30
        • 2021-10-29
        • 1970-01-01
        • 2021-07-20
        • 2016-09-06
        相关资源
        最近更新 更多