I will try my best to explain the issue. It is a little complex so please bear with me.
I have NodeJS API running on AWS. I am in the process of installing and running serverless locally on my machine. Without going into too much details of the reasons, I am using localstack with serverless to successfully run Node API endpoints locally (YAY!).
Below is my serverless.yml file
service: ONE-Cloud-API
frameworkVersion: ">=1.1.0 <2.0.0"
plugins:
- serverless-localstack
- serverless-offline
custom:
localstack:
debug: true
host: http://localhost
provider:
name: aws
runtime: nodejs4.3
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
functions:
getPatchStatus:
handler: services/lambdas/src/support.patchStatus
events:
- http:
path: v2/support/patchStatus/{id}
method: post
manageUser:
handler: services/lambdas/src/users.login
events:
- http:
path: v2/user/{exec}
method: post
resources:
Resources:
PatchStatusTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
TableName: my_phi_patchStatus
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
-
AttributeName: port
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
-
AttributeName: port
KeyType: S
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
What I am looking for is the functionality that is provided by Lambda Framework and how I can achieve the same in serverless.
On Aws:
I make a GET call to v2/support/patchStatus/{id} (see the yml file above, getPatchStatus). The Lambda Framework gets the call from API gateway (pass thru) and does the work of converting the GET call to POST call and converting the url param {id} to an post param in body called exec the structure looks like
{
"opts": {
"part" : "{id}"
}
}
I want to be able to do the same thing on serverless, is there a way that I can create one default handler that does this conversation for me and just call that which in turn will invoke the right lambda? (example services/lambdas/src/support.patchStatus).