npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generator-aws-lambda-code

v1.0.8

Published

auto generates aws lambda boilerplate code

Downloads

17

Readme

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
  • Usage
  • Deploy with AWS CLI
  • Deploy Using Jenkins
  • Running Lambda Locally

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