When I run
serverless invoke local --function get --path mocks/get-event.json
in my termal I get the following error message:
duplicated mapping key in “/Users/user/notes-app-api/serverless.yml” at line 57, column 5:
handler: get.main
The other handler is:
handler: create.main
My whole yml file:
service: notes-app-api
Create an optimized package for our functions
package:
individually: true
plugins:
- serverless-bundle # Package our functions with Webpack
- serverless-offline
- serverless-dotenv-plugin # Load .env as environment variables
provider:
name: aws
runtime: nodejs12.x
stage: prod
region: us-east-1
These environment variables are made available to our functions
under process.env.
environment:
tableName: notes
‘iamRoleStatements’ defines the permission policy for the Lambda function.
In this case Lambda functions are granted with permissions to access DynamoDB.
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: “arn:aws:dynamodb:us-east-1::”
functions:
Defines an HTTP API endpoint that calls the main function in create.js
- path: url path is /notes
- method: POST request
- cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
domain api call
- authorizer: authenticate using the AWS IAM role
create:
handler: create.main
events:
- http:
path: notes
method: post
cors: true
authorizer: aws_iam
get:
# Defines an HTTP API endpoint that calls the main function in get.js
# - path: url path is /notes/{id}
# - method: GET request
handler: get.main
events:
- http:
path: notes/{id}
method: get
cors: true
authorizer: aws_iam
I am at add a get note API in the serverless-stack.com. Does any one have any clues as to why it’s doing this and how to fix it?