Reputation: 1644
I am creating lambdas from the AWS SAM, mostly they are working well but I am not sure how to grant permission for these lambda's to be triggered by SQS. Whenever I build/package/deploy I am trying to manually add an SQS trigger from the console and I get the following error:
An error occurred when creating the trigger: The provided execution role does not have permissions to call ReceiveMessage on SQS (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException
I fully realize that it would be ideal to create the SQS with SAM as well, however I can't find decent guides, specifically about how to build yaml files for deploying with. I wondered if this error meant I need to add a policy to the template.yaml before the build/package/deploy. So I added the following policies to the yaml under Resources:MyFunction:Properties:policies:
- SQSSendMessagePolicy:
QueueName: "*"
- SQSPollerPolicy:
QueueName: "*"
I got these from here but I can't see a 'receive message from SQS' policy, I'm unsure where else to get one? Or if this is even the problem?
I also tried to add the following to the yaml:
Events:
MySQSEvent:
Type: SQS
Properties:
Queue:
!GetAtt arn:aws:sqs:eu-west-1:my_arn.my_queue
BatchSize: 10
However this gives me the following error when I try to deploy:
Template error: instance of Fn::GetAtt references undefined resource arn:aws:cloudformation:eu-west-1:my_arn
I have tried looking around for a guide to set up SQS through cloudformation but decent guides seem very elusive. The ones that are around seem overly verbose and complicated making them unsuitable for new users.
All I want to achieve is pass a list of events to an SQS (perhaps with a lambda) which will then queue another lambda to receive those events in batches of 10 (around 20,000 total). I need to be able to do this with SAM is the only caveat. I appreciate making lambdas on the console would make this a great deal easier but its not appropriate for version control.
So far I have looked at the following and can't see an obvious solution, the information seems not quite right to apply to my use case; SO question 1, SO question 2, aws alter stack tutorial, aws cloudformation templates, dzone tutorial, aws docs.
Would really appreciate any pointers/help/how-to-guides/full working solutions?
Many thanks
Upvotes: 4
Views: 3600
Reputation: 481
Your Events part should be like this
Events:
MySQSEvent:
Type: SQS
Properties:
Queue: !GetAtt QUEUE_NAME.Arn
Where QUEUE_NAME is the logical name of your SQS Queue in the Cloud Formation template
Upvotes: 2