Coder Social home page Coder Social logo

Comments (3)

aiden-sobey avatar aiden-sobey commented on July 30, 2024 1

There is very little documentation around this, so putting it out there to help others-
Using CDK you can deploy any Lambda to us-east-1 then reference it as a Lambda@Edge. As long as your lambda does not rely on any functionality not supported by edge lambdas it should work fine. I defined my lamdba as so:

import * as nambda from "aws-cdk-lib/aws-lambda-nodejs";
import * as lambda from "aws-cdk-lib/aws-lambda";

    this.lambda = new nambda.NodejsFunction(this, "auth", {
      handler: "handler",
      entry: path.join(__dirname, "../src/edge/auth.js"),
      runtime: lambda.Runtime.NODEJS_16_X,
      timeout: Duration.seconds(5),
      logRetention: RetentionDays.ONE_WEEK,
      bundling: {
        nodeModules: ["cognito-at-edge"],
      },
    });

This bundles the cognito-at-edge NPM package with my lambda, and this works at Edge which is awesome.
The code for my lambda is exactly as it is in my original post, and I reference it during creation of my CloudFront distribution:

this.distribution = new cf.Distribution(this, "server", {
    ...
    defaultBehavior: {
        edgeLambdas: [
            {
                eventType: cf.LambdaEdgeEventType.VIEWER_REQUEST,
                functionVersion: this.lambda.currentVersion,
            }
        ]
    }

I've also found a way to package props into the edge lambda at deploy time which is great, acts as a replacement for environment variables which Lambda@Edge does not have.

from cognito-at-edge.

karthikvadla avatar karthikvadla commented on July 30, 2024 1

Can you please explain more about packing props during deploy time? Are you using ssm?

from cognito-at-edge.

unitypark avatar unitypark commented on July 30, 2024

@aiden-sobey
hi! I have created a demo web app using this library for my edge function for cloudfront viewer request.

for bundling, in edge folder run "npm run webpack"

full code could be found at below link! 🚀
https://github.com/unitypark/aws-serverless-demos/tree/main/serverless-web-hosting/cloudfront-http-api-cognito

from cognito-at-edge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.