A barebones serverless function; Built with the Serverless Platform on a NodeJS
runtime; Deployed to AWS Lambda.
-
Install the AWS CLI
-
Run
aws configure
. It will prompt you to provide these settings:
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: ap-southeast-1
Default output format [None]: json
Note: Enter your preferred "default region name", for me, it's ap-southeast-1
. Also, these credentials will be saved into your ~/.aws
folder.
Needs >= Node v4
.
npm install -g serverless
A service on Serverless is a collection of all your AWS Lambda functions, the
events that trigger them and any AWS infrastructure resources they need. These
settings are specified in a file called serverless.yml
.
- Create a new service from a variety of templates by running
# Choose a template
serverless create --template [aws-nodejs / aws-nodejs-ecma-script / aws-python3 / hello-world ...]
# View all available templates
serverless create --help
-
Edit your
serverless.yml
file, or use the one included in this repository. Moreserverless.yml
settings may be found on the official Serverless documentation site. -
Deploy your Service using your default AWS credentials by running
serverless deploy -v
this deploys all changes to your Functions, Events or Resources in serverless.yml
Deploy your function without re-deploying your service with
serverless deploy function -f hello
Invoke and fetch function logs with
serverless invoke -f hello -l
Alternatively, if you want to do this within your AWS Lambda Management Console, navigate to "Monitoring" > "View logs in CloudWatch" > Click on a log stream.