Serverless Framework AWS NodeJS Example

This template demonstrates how to deploy a simple NodeJS function running on AWS Lambda using the Serverless Framework. The deployed function does not include any event definitions or any kind of persistence (database). For more advanced configurations check out the examples repo which include use cases like API endpoints, workers triggered by SQS, persistence with DynamoDB, and scheduled tasks. For details about configuration of specific events, please refer to our documentation.

Usage

Deployment

In order to deploy the example, you need to run the following command:

serverless deploy

After running deploy, you should see output similar to:

Deploying "aws-node" to stage "dev" (us-east-1)
✔ Service deployed to stack aws-node-dev (90s)
functions:
hello: aws-node-dev-hello (1.5 kB)

Invocation

After successful deployment, you can invoke the deployed function by using the following command:

serverless invoke --function hello

Which should result in response similar to the following:

{
"statusCode": 200,
"body": "{\"message\":\"Go Serverless v4.0! Your function executed successfully!\"}"
}

Local development

The easiest way to develop and test your function is to use the Serverless Framework's dev command:

serverless dev

This will start a local emulator of AWS Lambda and tunnel your requests to and from AWS Lambda, allowing you to interact with your function as if it were running in the cloud.

Now you can invoke the function as before, but this time the function will be executed locally. Now you can develop your function locally, invoke it, and see the results immediately without having to re-deploy.

When you are done developing, don't forget to run serverless deploy to deploy the function to the cloud.