Skip to content

x0rCTF/Serverless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 

Repository files navigation

Serverless framework

visitors

The Serverless Framework – Builds applications on AWS Lambda and other next-gen cloud services, that auto-scale and only charge you when they run. This lowers the total cost of running and operating your apps, enabling you to build more and manage less.

The Serverless Framework is a command-line tool that uses easy and approachable YAML syntax to deploy both your code and cloud infrastructure needed to make tons of serverless application use-cases. It's a multi-language framework that supports Node.js, Typescript, Python, Go, Java, and more. It's also completely extensible via over 1,000 plugins that can add more serverless use-cases and workflows to the Framework.

Actively maintained by Serverless Inc.

Preparing environment for Serverless framework

nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.

Installing the latest Node.js LTS version using NVM

Installing Serverless framework

npm install -g serverless

Creating a new serverless project on AWS using Node.js

Here we specified that we will use aws-nodejs as a template, which will be stored in ~/Mentorship/, and the name of our project is SLSFunc. handler.js - has our JavaScript code. The Lambda function handler is the method in your function code that processes events. When your function is invoked, Lambda runs the handler method. When the handler exits or returns a response, it becomes available to handle another event. serverless.yml - the main config file that defines your functions, events and resources. For full config options, check the docs.

Deployin the code.

How serverless deploy works

When you run serverless deploy, two steps are run behind the scenes. Serverless Framework first runs serverless package to package your code and build a CloudFormation template. By default, the artifact is generated in the .serverless/ directory of your project root with the following contents:

  1. A zip file with the Lambda code for your service. Or a zip file for each Lambda function in your service if individual packaging is turned on.
  2. A CloudFormation template file that describes the resources defined in your serverless.yml.
  3. A serverless-state.json file that is used internally by Serverless Framework.

After the artifact is generated, Serverless then deploys this package by:

  1. Uploading the zip file to S3.
  2. Updating the CloudFormation template with S3 paths for the Lambda zip files.
  3. Submitting the template to CloudFormation to kick start the deployment.

Invoking the request

We can trigger Lambda functions from the CLI with the following syntax:

sls invoke -f <$FUNCTION> --aws-profile <$PROFILEE>

we can also test it locally before deploying within our environment:

sls invoke local -f <$FUNCTION>

Reading Cloudwatch logs using serverless cli

We can read Cloudwatch logs from the CLI with the following syntax:

sls logs -f <$FUNCTION> --aws-profile <$PROFILE>

CloudWatch check:

Modifying and updating the code

To modify the code we can use pretty much any text editor, in this case, I am just going to do that using nano.

To update the code we are going to deploy again and invoke the function to see its output.

To confirm that our code is successfully modified and updated, we can also check it on CloudWatch.

Cleaning up..

After we successfully created the environment, installed Serverless Framework to create our project, deployed the code, invoked the request, read logs using the serverless CLI and CloudWatch - it is time to clean up!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published