Hello World - Python Example from Scratch

https://github.com/koushikvikram/serverless-python-hello-world

Hello World Example - Node.js template

Prerequisites:

cd into your project directory and create an application using serverless CLI with the help of one of the templates already available with serverless using following command.

serverless create --template aws-nodejs-docker

This will create following files:

  1. app.js file to hold business login in handler method.
  2. Dockerfile, to package the Node.js app in a docker image.
  3. serverless.yml, for declaring deployment configuation variables.

From the same directory, run

serverless package

To deploy the serverless application, run the following command from the same directory

serverless deploy

Upon completion, we can see the following resources created in the AWS console:

  1. CloudFormation stack with its artifacts in S3 bucket.
  2. Lambda Function created with type docker.
  3. Roles and policies
  4. CloudWatch Log Groups for application logs.
  5. Docker Image in ECR

We can test the app by running the following command in the same directory

serverless invoke -f hello -d '{"msg": "Cheers !!"}'                                               

RESPONSE:

{
    "statusCode": 200,
    "body": "{\n  \"message\": \"Hello, world! Your function executed successfully! Cheers !!\"\n}"
}

Finally, we can deprovision/clean up all the deployed components by running the following command in the same directory

serverless remove

Reference:

Things to Consider

To prevent accidental deletion, either:

Production-Ready Serverless Course

Source: Production-Ready Serverless - Operational Best Practices