question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-lambda] CurrentVersion not available for imported Lambda@Edge function

See original GitHub issue

❓ General Issue

The Question

I’m only able to get .currentVersion on the new lambda function, but not on the imported one.

image

Is it possible to get .currentVersion property of the imported Lambda@Edge function?

Environment

  • CDK CLI Version: 1.60.0
  • Node.js Version: v14.8.0
  • OS: OSX Mojave
  • Language (Version): TypeScript (3.8.3)

Other information

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
jogoldcommented, Aug 24, 2020

@robertd like I proposed in #9892 with fromVersionArn():

const functionVersion = lambda.Version.fromVersionArn(this, 'Version', 'arn:aws:lambda:us-east-1:1234567890:function:test-cloudfront:1');

const distro = new cloudfront.Distribution(this, "cf-distro", {
  defaultBehavior: {
    origin: new origins.S3Origin(testBucket),
    viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
    edgeLambdas: [
       {
         functionVersion, // <== the imported version is used here
         eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST
       },
    ]
  },
  certificate: acmCertificate,
  defaultRootObject: "index.html",
  priceClass: cloudfront.PriceClass.PRICE_CLASS_100,
});
1reaction
robertdcommented, Aug 24, 2020

@nija-at I’m trying to import an existing L@E function. As you know, Lambda@Edge functions can only be created in us-east-1; the default region we use is us-west-2. This function (it’s current version) is used as a parameter for the CloudFront distribution construct.

const lambdaEdge = lambda.Function.fromFunctionArn(this, "test", "arn:aws:lambda:us-east-1:1234567890:function:test-cloudfront:1");

const distro = new cloudfront.Distribution(this, "cf-distro", {
  defaultBehavior: {
    origin: new origins.S3Origin(testBucket),
    viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
    edgeLambdas: [
       {
         functionVersion: lambdaEdge.currentVersion, // <== This doesn't exist on the imported lambda function
         eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST
       },
    ]
  },
  certificate: acmCertificate,
  defaultRootObject: "index.html",
  priceClass: cloudfront.PriceClass.PRICE_CLASS_100,
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

class EdgeFunction (construct) · AWS CDK
A Lambda@Edge function added to default behavior of a Distribution // and ... For valid values, see the Runtime property in the AWS...
Read more >
Using Lambda@Edge with CloudFront to configure redirect ...
I'm a big fan of cool URLs and not breaking the internet and so over the years I've ... import * as lambda...
Read more >
Lambda@Edge Archives - Jayendra's Cloud Certification Blog
AWS Lambda functions must complete execution within 300 900 seconds. ... Each function has a single, current version of the code and there...
Read more >
Ask question - AWS re:Post
I tried creating a demo for VueJS SSR using Lambda@Edge and using AWS CDK v2. ... Function, Runtime } from 'aws-cdk-lib/aws-lambda'; import {...
Read more >
Dynamically Configure Your Lambda@Edge Functions
With Lambda@Edge we not allow to use environment variables. At all. Period. Origin-Request Example. For origin-request event functions there is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found