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

Role definition for multiple SQS queues is duplicated #11684

Closed
4 tasks done
ROSeaboyer opened this issue Jan 16, 2023 · 2 comments · Fixed by #11685
Closed
4 tasks done

Role definition for multiple SQS queues is duplicated #11684

ROSeaboyer opened this issue Jan 16, 2023 · 2 comments · Fixed by #11685

Comments

@ROSeaboyer
Copy link
Contributor

Are you certain it's a bug?

  • Yes, it looks like a bug

Is the issue caused by a plugin?

  • It is not a plugin issue

Are you using the latest v3 release?

  • Yes, I'm using the latest v3 release

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

If I have two lambda functions, each consuming from a separate SQS queue, the resulting IAM role has the SQS section defined as so:
{ "Effect": "Allow", "Action": [ "sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes" ], "Resource": [ "arn:aws:sqs:ca-central-1:864919514680:test-queue-1" ] }, { "Effect": "Allow", "Action": [ "sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes" ], "Resource": [ { "Fn::GetAtt": [ "TestQueue2", "Arn" ] } ] }

Instead, it should be defined as this:
{ "Effect": "Allow", "Action": [ "sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes" ], "Resource": [ "arn:aws:sqs:ca-central-1:864919514680:test-queue-1", { "Fn::GetAtt": [ "TestQueue2", "Arn" ] } ] }

I've found that the first option makes the role hit the 10,644 character limit too quickly for no apparent reason, while the second still seems fine for the time being.

The change I've patched to prevent this just moves the PolicyDocument update for SQS in lib/plugins/aws/package/compile/events/sqs.js outside the loop of all functions; I'm fine pushing that up, but let me know if there's a more desired approach for this.

Service configuration (serverless.yml) content

service: ROSeaboyer-test
provider:
  name: aws
  region: ca-central-1
  runtime: python3.9
  iam:
    role:
      statements:
        - Effect: Allow
          Action:
            - xray:PutTraceSegments
          Resource: '*'
functions:
  testOne:
    name: test-lambda
    handler: test.handler
    package:
      patterns:
        - '*/test.py'
    events:
      - sqs:
          arn: arn:aws:sqs:ca-central-1:<account-id>:test-queue-1

  testTwo:
    name: test-lambda-two
    handler: test.handler
    package:
      patterns:
        - '*/test.py'
    events:
      - sqs:
          arn: !GetAtt TestQueue2.Arn

resources:
  Resources:
    TestQueue2:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: test-queue-2

Command name and used flags

serverless package

Command output

N/A

Environment information

Framework Core: 3.26.0 (local)
Plugin: 6.2.2
SDK: 4.3.2
@medikoo
Copy link
Contributor

medikoo commented Jan 16, 2023

@ROSeaboyer I wouldn't call it a bug, as it doesn't break anything.

Nonetheless, an improvement to that is definitely welcome. We're open for PR!

@ROSeaboyer
Copy link
Contributor Author

@medikoo Makes sense, as I was unsure which direction to report this as. PR #11685 created to address this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants