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 🙏

© 2022 – Pkg Stats / Ryan Hefner

@nona-creative/aws-cdk-standard-cloudfront-lambdas

v1.1.13400

Published

AWS CDK Construct for the standard edge lambda functions you are likely to need. Provides index documents and http basic auth.

Downloads

203

Readme

aws-cdk-standard-cloudfront-lambdas

This package supplies a CDK construct that creates viewer-request and origin-request edge lambdas in us-east-1, implementing useful standard features, specifically:

  • Root index documents, useful if you are hosting your site in a non public S3 bucket
  • HTTP basic authentication
  • Image resizing and conversion to efficient formats (webp, avif) if the browser supports them

Versioning

The minor version of the package is synchronized to the CDK version used.

Prerequisites

  • An AWS account and relevant profile configured
  • A CloudFront distribution to attach the lambdas to
  • An S3 bucket to read images from and save converted images to

WebP and Avif

If these are enabled in the configuration, they will be generated, cached, and returned for browsers that support them. If desired, quality for these formats can be specified in the query string with wq and aq parameters.

Image resizing

  • Desired width and height are specified in the query string with w and h parameters.
  • Either one can or both be ommitted.
  • If specifying both width and height, cropping can be selected with c. Default is no cropping.
  • Images will not be scaled larger, so if a size larger than an image is requested, the original image size will be returned.
  • Allowed dimensions can be specified to override defaults. Specifying 0 for a dimension allows that dimension to be ommitted.
  • Quality for jpeg or png resizes can be specified with jq or pq parameters

Example usage

new AWSStandardCloudFrontLambdas(this, 'CloudfrontLambdas', {
  defaultRootObject: 'index.html',
  basicAuthentication: {
    user: 'aUser',
    password: 'hunter2',
  },
  imageProcessing: {
    enableResize: true,
    enableWebP: true,
    enableAvif: true,
    processedImageBasePath: 'convert',
    originBucketName: 'aBucket',
  },
  stackId: 'my-edge-stack',
})

const bucket = new Bucket(this, 'S3CloudFrontSiteBucket', { bucketName: 'nona.digital' })
const originAccessIdentity = new OriginAccessIdentity(this, 'S3CloudFrontWebsiteOAI')
bucket.grantRead(originAccessIdentity)
new CloudFrontWebDistribution(this, 'distribution', {
  originConfigs: [
    {
      s3OriginSource: {
        s3BucketSource: bucket,
        originAccessIdentity,
      },
      // Some origin e.g. S3
      behaviors: [
        {
          isDefaultBehavior: true,
          lambdaFunctionAssociations: this.awsStandardCloudFrontLambdas.lambdaFunctionAssociations,
        },
      ],
    },
  ],
})

this.awsStandardCloudFrontLambdas.grantBucketRights(bucket)

Notes

  • You need to have the correct AWS_PROFILE environment variable set, as the CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION are picked up from the AWS_PROFILE environment variable
  • If you use this construct in a stack deploying anywhere except us-east-1, an additional stack for your edge lambdas will be created in us-east-1
  • You will need to have us-east-1 cdk bootstrapped
  • As per the example above, you will need to grant the origin response lambda read and write access to the bucket your images are served from

See example app for a complete example