Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue: AccessDenied to resource https://sqs.us-east-1.amazonaws.com #236

Closed
raiseandfall opened this issue Jun 28, 2022 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@raiseandfall
Copy link

raiseandfall commented Jun 28, 2022

Description

After deploying, sending a message always throws an access denied error (error: AccessDenied: Access to the resource https://sqs.us-east-1.amazonaws.com/ is denied):

Full error:

{ value: { error: AccessDenied: Access to the resource https://sqs.us-east-1.amazonaws.com/ is denied. at Request.extractError (/opt/nodejs/node_modules/aws-sdk/lib/protocol/query.js:50:29) at Request.callListeners (/opt/nodejs/node_modules/aws-sdk/lib/sequential_executor.js:106:20) at Request.emit (/opt/nodejs/node_modules/aws-sdk/lib/sequential_executor.js:78:10) at Request.emit (/opt/nodejs/node_modules/aws-sdk/lib/request.js:686:14) at Request.transition (/opt/nodejs/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/opt/nodejs/node_modules/aws-sdk/lib/state_machine.js:14:12) at /opt/nodejs/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request.<anonymous> (/opt/nodejs/node_modules/aws-sdk/lib/request.js:38:9) at Request.<anonymous> (/opt/nodejs/node_modules/aws-sdk/lib/request.js:688:12) at Request.callListeners (/opt/nodejs/node_modules/aws-sdk/lib/sequential_executor.js:116:18) { code: 'AccessDenied', time: 2022-06-28T16:37:44.889Z, requestId: '09a7e81d-722b-56b8-8601-b32842b3e67a', statusCode: 403, retryable: false, retryDelay: 91.4007833446157 } } } 

How to Reproduce

serverless.yml

functions:
  - ${file(./src/handlers/handlers.yml)}
 
constructs:
  queueTest:
    type: queue
    fifo: true
    worker:
      handler: ./src/handlers/processQueueHandler.processQueueHandler

handlers.yml

publisherHandler:
  handler: src/handlers/handlers/publisherHandler.publisherHandler
  iamRoleStatements:
    - Effect: 'Allow'
      Action:
        - 'lambda:InvokeFunction'
        - 'lambda:InvokeAsync'
      Resource: 'arn:aws:lambda:us-east-1:xxxxxxxxxxxxx:function:some-function'
  environment:
    QUEUE_URL: ${construct:assetsToAddQueueStaging.queueUrl}
  events:
    - httpApi:
        path: /api/publishToQueue
        method: post

Please note that publisherHandler also invoke another lambda, thus the iam role there

publisherHandler.ts

const sqs = new SQS({
    apiVersion: 'latest',
    region: process.env.AWS_REGION
});

await sqs.sendMessage({
  QueueUrl: process.env.QUEUE_URL,
  MessageBody: JSON.stringify({
    key: 'value'
  })
}).promise();

Additional Information

  • Serverless 3.17.0
  • Serverless-lift 1.19.0
  • QueueUrl has the right value in the publisher handler
  • I did not set any specific IAM permissions since the doc didn't say so
  • when looking at my publisher lambda Permissions, only the one I specifically set shows up. There is no SQS permission.

There is obviously a permission issue, but I can't figure out what.

@raiseandfall raiseandfall added the bug Something isn't working label Jun 28, 2022
@raiseandfall raiseandfall changed the title SQS Access Denied to AccessDenied: Access to the resource https://sqs.us-east-1.amazonaws.com is denied Jun 28, 2022
@raiseandfall raiseandfall changed the title AccessDenied: Access to the resource https://sqs.us-east-1.amazonaws.com is denied AccessDenied to resource https://sqs.us-east-1.amazonaws.com Jun 28, 2022
@raiseandfall raiseandfall changed the title AccessDenied to resource https://sqs.us-east-1.amazonaws.com Queue: AccessDenied to resource https://sqs.us-east-1.amazonaws.com Jun 28, 2022
@raiseandfall
Copy link
Author

raiseandfall commented Jun 28, 2022

I ended up setting the IAM Role Statement directly on the publish handler definition:

publisherHandler:
  handler: src/handlers/handlers/publisherHandler.publisherHandler
  iamRoleStatements:
    - Effect: 'Allow'
      Action:
        - 'sqs:SendMessage'
      Resource: ${construct:queueTest.queueUrl}

First I thought that my existing IAM Role Statement on the publish handler was overwriting the SQS one, but even when commenting out the whole iamRoleStatements block I'm still getting the AccessDenied issue.
It's working now, but it would be interested to figure out why the permission are not set automatically, as specified in the doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant