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

gulp-awslambda-3-status

v2.0.0

Published

A wrapper for checking the status of an AWS Lambda function

Downloads

342

Readme

gulp-awslambda-3-status

license

A wrapper for checking the status of an AWS Lambda function

Install

$ npm install --save-dev gulp-awslambda-3-status

Rationale

As of October 2021 the AWS Lambda interface has been updated to require querying the Function State before performing an update of function code. See https://docs.aws.amazon.com/lambda/latest/dg/functions-states.html. A typical Lambda gulp tool-chain will contain multiple Lambda commands in sequence such as upload, publish and update function configuration. Between each of these steps the Function State must be checked. This module simplifies the checking of this status and automatically checks the status of the function up to 10 times (default) at 1 second intervals.

The method used to check status is as follows:

  • Call checkLambdaStatus(FunctionName, lambda) before running any Lambda command that would modify the function
  • Check status will monitor the result of GetFunctionConfigurationCommand for State = 'Active' and LastUpdateStatus !== 'InProgress'.
  • If the state requirements are not met, up to 10 retries (default) at a 1 second interval are tried to allow AWS Lambda to complete it's initialization of the previous update.
  • This function will throw an error if the 10 retires are exhausted or if the Lambda function returns an error state.
  • This function will log 'Waiting for update to complete "${FunctionName}"' to the console each time a retry situation is encountered when set to verbose.

Version 2.0

Version 2.0 is written with ES modules. An import statement is required to use the package.

Usage

AWS Credentials and Configuration

As this function is called as part of an AWS Lambda tool chain a pre-configured LambdaClient must be provided to this function as its second argument. Details for configuring the client can be found in the AWS SDK documentation. At a bare minimum region and credentials should be provided, although credentials will be pulled from environment variables or an ini file if present in the environment.

Basic Workflow

checkLambdaStatus returns a promise so it is critical that the gulp task calling this funcition be async and that the function is called with await.

import { LambdaClient } from '@aws-sdk/client-lambda';
import checkLambdaStatus from './index.mjs';

// configure lambda client
const lambdaClient = new LambdaClient({
	region: 'us-east-1',
});

// function name to query
const functionName = 'gulp-awslambda-3-status-test';

// create a task
const checkStatus = async () => {
	// check status before making updates to function
	await checkLambdaStatus(functionName, lambdaClient);

	// lambda function is ready for changes
	// call code to upload, publish, etc on lambda function
};

Code similar to the example is provided in the gulp task checkStatus. You will need to set the function name and region in this file before running gulp.

npx gulp checkStatus

API

checkLambdaStatus(functionName, lambdaClient, count, verbose)

functionName

A string with the name of the Lambda function to be queried.

lambdaClient

A pre-configured LambdaClient instance.

count = 10

Maximum number of retries at a 1 second interval.

verbose = false

When true, provide a status every time the function status is queried including the number of seconds (retries) remaining.