serverless: SQS trigger not created?
This is a (Bug Report)
Description
For bug reports:
- What went wrong?
I am using AWS as my provider. I have used a number of event triggers and needed to use SQS as an event trigger for my lambda.
When I specify an ARN or use an Fn::ImportValue, no event source mapping is created in the .serverless directory (thus, no event trigger for that SQS lambda appears).
I followed this documentation: https://serverless.com/framework/docs/providers/aws/events/sqs/
- What did you expect should have happened?
An event source mapping should be created and when I view the lambda panel in AWS I should see it as a trigger on the GUI. I can create it manually (but I would prefer to allow serverless to create it for me).
- What was the config you used? See the below markdown snippet which corresponds to the function.
The only section that has been added/changed is below (out of a large yaml):
functions:
nameOfSQSFunction:
handler: directory/nameofservice.service
timeout: 30
events:
- sqs:
batchSize: 10 # max size is currently 10
enabled: true
arn:
Fn::ImportValue: ${opt:stage}-exportedIdFromAWS
I also tried specifying the ARN directly:
functions:
nameOfSQSFunction:
handler: directory/nameofservice.service
timeout: 30
events:
- sqs:
batchSize: 10 # max size is currently 10
enabled: true
arn: arn:aws:sqs:region:XXXXXX:myQueue
Initially I was concerned maybe it was a permissions issue somewhere and added sqs:* under permissions but it appears this is related to event source mapping (?) not really SQS itself, so I’ve since removed that.
- What stacktrace or error message from your provider did you see?
There is no stack trace.
For feature proposals:
- What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.
- If there is additional config how would it look
Similar or dependent issues:
- #5085 - issue for SQS support / PR
- #5105 - checked for the same mistake (version of sls)
- #5102 - disabled trigger by default (which is why i put enabled: true) – But if you look at this comment they are examining the source mapping: https://github.com/serverless/serverless/issues/5102#issuecomment-403222199 which is simply not present in my .serverless/update stack file
Disabled by default
Additional Data
I was able to recreate my own mapping with:
Resources:
mappingName:
Type: AWS::Lambda::EventSourceMapping
Properties:
BatchSize: 10
EventSourceArn:
Fn::ImportValue: ${opt:stage}-<<exportedId>>
FunctionName: ${self:service}-${self:custom.stage}-<<functionName>>
I will try to use this until I can get it working with serverless’ specification under the function.
- Serverless Framework Version you’re using: v1.28.0 and v1.29.2 (attempted this on both versions)
- Operating System: Mac OS X High Sierra
- Stack Trace: No stack trace
- Provider Error messages: No errors
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 9
- Comments: 21 (3 by maintainers)
@poisa Try indenting the lines with ‘arn’ and ‘batchSize’ 2 more spaces to the right. I believe your yaml format is invalid as above. Here is one of my configs that I have working with 1.32.0, but it was working with 1.30 as well.
I had a typo where I used
eventinstead ofevents.Wrong:
Correct:
Tracked this down by running
sls printwhere I sawevents: []. That made me check the definition again.I also experienced indent issues, which is hard to spot as they just get silently ignored. But anyway, would be great if yaml format was validated prior to deploys, and preferably an error stating what is wrong. 😃
Experiencing the same on 1.32.0
In my case this works:
But the actual documented format doesn’t:
So far I’ve found no way of getting the
batchSizeto be recognized in my lambda function. No matter what I do it gets set as the default of 10.I am experiencing the same issue. No SQS queue is added to the Lambda function in the Triggers section after it is deployed.
From @madhuravius 's comment, I tried adding the latest version to
serverless.ymlas described in the docs:And tried deploying again. But the SQS trigger still won’t be created.
Just ran into this. Fixed it by increasing the indentation for the
arnandbatchSizeparameters with 2 more spaces.I had the same issue with the SQS trigger not being created and no error messages or CFT errors. The fix for me was to increase the indentation for the arn and batchSize parameters.
serverless --version: Framework Core: 1.60.1 Plugin: 3.2.6 SDK: 2.2.1 Components Core: 1.1.2 Components CLI: 1.4.0
Thanks to the comments above for pointing me in the right direction!
@Bartinger for your function, the indentation below
- sqsdoesn’t look to be enough.