12

I am trying to deploy the lambda function along with the serverless.yml file to AWS, but it throw below error

The following is the function defined in the YAML file

functions:
 s3-thumbnail-generator:
 handler:handler.s3_thumbnail_generator  
   events:
     - s3:
       bucket: ${self:custom.bucket}
       event: s3.ObjectCreated:*
       rules:
       - suffix: .png

plugins:
  - serverless-python-requirements  

Error I am getting:

can not read a block mapping entry; a multiline key may not be an implicit key in serverless.yml" at line 45, column 10:

I would need to understand how to fix this issue in YAML file in order to deploy to the function to AWS?

Anthon
  • 69,918
  • 32
  • 186
  • 246
Hari
  • 151
  • 1
  • 2
  • 5
  • 1
    Please note that the file format is called YAML and the recommended file extension has been `.yaml` since 2006. [YML](https://fdik.org/yml/) is about as old as YAML but something completely different. – Anthon May 01 '19 at 17:52
  • I have found it difficult to debug syntax errors like this in the online Swagger editor. These issues are more easily identified in text editors like SublimeText, where colour coding is used to highlight syntax problems. – OneXer May 14 '21 at 15:19

2 Answers2

7

The problem is that there is no value indicator (:) at the end of the line:

handler:handler.s3_thumbnail_generator

so the parser continues to try and gather a multi-line plain scalar by adding events followed by a value indicator. But a multi-line plain scalar cannot be a key in YAML.

It is unclear what your actual error is. It might be that you need to add the value indicator and have a colon emmbedded in your key:

functions:
 s3-thumbnail-generator:
 handler:handler.s3_thumbnail_generator:
   events:
     - s3:
       bucket: ${self:custom.bucket}
       event: s3.ObjectCreated:*
       rules:
       - suffix: .png

plugins:
  - serverless-python-requirements 

Or it could be that that colon should have been a value indicator (which usually needs a following space) and you were sloppy with indentation:

functions:
  s3-thumbnail-generator:
  handler: handler.s3_thumbnail_generator  
  events:
     - s3:
       bucket: ${self:custom.bucket}
       event: s3.ObjectCreated:*
       rules:
       - suffix: .png

plugins:
  - serverless-python-requirements 
Anthon
  • 69,918
  • 32
  • 186
  • 246
  • Thanks @Anthon for the replay.. However the issue is not fxed yet. i added value indicator (:) as suggested here handler:handler.s3_thumbnail_generator: But iam getting duplicate error as seen below duplicated mapping key in serverless.yml at line 92, column -1450: functions: I changed all the way as you mentioned, but still it didn't help. Let me know please if i need to provide more details to get any solution for the same? Much appreciated.. Thanks – Hari May 02 '19 at 05:27
  • 1
    What I need is a link to the example or documentation you based your code upon. (edit it into your question, and leave out any **UPDATE** or **EDIT**). I have no exeperience with AWS, only with YAML and not every valid YAML document will be meaningful for AWS. – Anthon May 02 '19 at 06:07
0

If it is your original file there is a syntax error in your YAML file. I added a note under the line of possible error:

functions:
 s3-thumbnail-generator:
 handler:handler.s3_thumbnail_generator  
   events:
     - s3:
       bucket: ${self:custom.bucket}
       event: s3.ObjectCreated:*
       rules:
       - suffix: .png
       ^^^ this line should be indented one level

plugins:
  - serverless-python-requirements
superkeci
  • 151
  • 2
  • 3