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

@ahrefs/bs-aws-lambda

v1.0.0

Published

bucklescript types for aws-lambda

Downloads

30

Readme

bs-aws-lambda

bs-aws-lambda is a set of types to use when creating AWS lambda handlers.

Those types are inspired by the @types/aws-lambda package with typescript types.

Installation

yarn add @ahrefs/bs-aws-lambda

or to follow the master version:

yarn add https://github.com/ahrefs/bs-aws-lambda.git

Usage

Add @ahrefs/bs-aws-lambda to the bs-dependencies of bsconfig.json.

Then when you create a function handler for a lambda, you can annotate it with one of AwsLambda.Scheduled.handler, AwsLambda.Dynamodb.streamHandler, AwsLambda.Sns.handler, etc. This way you are sure to expose a function which respect the signature expected by Lambda and you get types information for all the parameters this function will receive.

Example

A full example is documented here. It is using the sources from the example directory.

Simple echo function for the API Gateway. This might seem a little verbose compare to a typescript version. But using this package, you are sure to handle all the possible cases where a value is actually null or base64 encoded. Plus the returned object given to the callback will always have the expected fields and types.

let handler: AwsLambda.APIGatewayProxy.handler =
  (event, _context, cb) => {
    open AwsLambda.APIGatewayProxy;
    let parameter =
      event
      |. Event.queryStringParameters
      |> Js.Option.andThen((. params) => Js.Dict.get(params, "userid"));
    switch (parameter) {
    | Some(userid) => Js.log2("executing lambda for", userid)
    | None => Js.log("executing lambda for anonymous user")
    };
    let result =
      switch (event |. Event.body) {
      | None =>
        Js.log("error: no body available in the request");
        result(
          ~body=`Plain({|{"status": "no body available in the request"}|}),
          ~statusCode=400,
          (),
        );
      | Some(body) =>
        Result.make(~statusCode=200, ~body, ~isBase64Encoded=event |. Event.isBase64Encoded, ())
      };
    cb(Js.null, result);
    Js.Promise.resolve();
  };

The typescript equivalent of the type annotation is actually more verbose:

export const handle: Lambda.APIGatewayProxyHandler = async (
    event: Lambda.APIGatewayEvent,
    context: Lambda.Context,
    cb: Lambda.APIGatewayProxyCallback) => {
}