New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

generator-aws-lambda-code

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generator-aws-lambda-code

auto generates aws lambda boilerplate code

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

generator-aws-lambda-code NPM version

generator-aws-lambda-code helps in generating scaffold code for AWS lambda function. The module will generate skeleton code for interacting with MongoDB cluster and performing basic CRUD operations. It has ability to generate the code both in Typescript and Javascript based on the user selection. The module uses AWS Serverless Application Model (SAM) framework to build the lambda on AWS. The lambda function will be deployed behind an APIGateway and will be scured using AWS API_Key service. The module enables you to implement Continous Integration and Continuous Deployment(CICD) using jenkins by generating Jenkinsfile . It also includes template code for unit testing using Mocha and integration testing, code coverage using istanbul.

Contents

Installation

First, install Yeoman and generator-aws-lambda-code using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-aws-lambda-code

Usage

Generate your new project:

yo aws-lambda-code

Answer the questionnaire.

Note: For the question Name of the default resource/collection (please provide the singular form of collection name) , Please provide the mongo collection name on which your lambda function performs CRUD operations

Create and configure the following parameters as text strings under SSM parameter store in your AWS account

1. mongo_user
2. mongo_password
3. mongo_cluster
4. mongo_db_name

Note: Generator code has mongo_password parameter in environment variables which will get resolved during deployment phase. For the security purpose, configure mongo_password SSM parameter as KMS encrypted string instead of plain text and read the value dynamically during runtime using AWS SDK rather than putting it in environment variables.

Deploy with AWS CLI

  • Build the code archive
npm run build
  • Create s3 bucket for the deployment artifacts
aws s3 mb s3://<<Bucket_name>>
  • Install SAM local. For instructions please follow the link

  • Run the following commands

sam package --template-file sam.yml --output-template-file ./<<Output-Template-File-Name.yml>> --s3-bucket <<Bucket_name>>
sam deploy --template-file <<Output-Template-File-Name.yml>> --stack-name <<Aws-Stack-Name>> --capabilities CAPABILITY_IAM

Deploy Using Jenkins

  • Install nodejs in jenkins Manage Jenkins -> Manage Plugins -> Available Tab -> select NodeJs and install

  • Configure nodejs version globally in jenkins Manage Jenkins -> Global Tool Configuration -> NodeJS -> click Add NodeJS

    alt text

  • Install CloudBees AWS Credentials and AWS SAM plugins in jenkins Manage Jenkins -> Manage Plugins -> Available Tab. Search for CloudBees AWS Credentials and AWS SAM and install them.

  • Configure AWS access key and secret key in jenkins

    alt text

  • Create a pipeline job and provide git repository details and credentials to connect to git.

    alt text

    alt text

  • Open the pipeline job and click build now. This should create your lambda function and other related resources in your aws account

Running the lambda using SAM Local

We assume you have installed AWS SAM Local on to your commputer.

npm run build
sam local start-api -t ./sam.yml

License

MIT © nagakedari

Keywords

yeoman-generator

FAQs

Package last updated on 29 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts