aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[aws-lambda] Cannot get ARN of version obtained via currentVersion

Open rigsbyt opened this issue 6 years ago • 4 comments

.currentVersion causes the logical ID of the version resource to be overridden in the prepare step.

I am trying to get the ARN of a version resource elsewhere via .functionArn on the resource retrieved by .currentVersion

This is causing: Error [ValidationError]: Template format error: Unresolved resource dependencies [MyFunctionCurrentVersionCAC64D50] in the Resources block of the template

I can see in the generated template that it's trying to retrieve the Arn via: Ref MyFunctionCurrentVersionCAC64D50 But the resource's logical ID is now: MyFunctionCurrentVersionCAC64D5034e479583e6893cf9f24d9284e5bb773

Reproduction Steps

const lambda1 = new Lambda(scope, 'Lambda1', {...}) const lambda2 = new Lambda(scope, 'Lambda2', { enviornment: { dependentLambda: lambda1.currentVersion.functionArn }})

Error Log

This is causing: Error [ValidationError]: Template format error: Unresolved resource dependencies [Lambda1CAC64D50] in the Resources block of the template

Environment

  • CLI Version : 1.47.1
  • **Framework Version: 1.47.1 **
  • Node.js Version: 14.2.0
  • OS : Mac OS X Catalina
  • **Language (Version): 3.9.2 **

Other


This is :bug: Bug Report

rigsbyt avatar Jul 01 '20 17:07 rigsbyt

I'm encountering the same problem

lanefelker avatar Jul 07 '20 21:07 lanefelker

Unfortunately, I'm unable to reproduce this error. I was able to deploy the following app and check that the environment variable is correctly set.

#!/usr/bin/env node
import { App, Stack } from '@aws-cdk/core';
import { Code, Function, Runtime } from '@aws-cdk/aws-lambda';

const app = new App();
const stack1 = new Stack(app, 'myfirststack');

const fn1 = new Function(stack1, 'fn1', {
  code: Code.fromInline('foo'),
  runtime: Runtime.NODEJS_12_X,
  handler: 'index.handler'
});

new Function(stack1, 'fn2', {
  code: Code.fromInline('foo'),
  runtime: Runtime.NODEJS_12_X,
  handler: 'index.handler',
  environment: {
    dependentLambda: fn1.currentVersion.functionArn 
  }
});

Checking the environment variable after deployment -

⇒  aws lambda get-function-configuration --function-name myfirststack-fn2BD2E493A-1X4YEDLT2XJUE --query Environment
{
    "Variables": {
        "dependentLambda": "arn:aws:lambda:eu-west-1:664773442901:function:myfirststack-fn117719295-GG6MWZJF1YB4:1"
    }
}

If you're still seeing this error, please provide a similar minimal reproduction CDK app.

nija-at avatar Jul 16 '20 10:07 nija-at

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Jul 24 '20 06:07 github-actions[bot]

Hi, I have the same problem with when I pass a variable enviroment to lambda to take the first lambda enviroment. const COMMAND_LAMBDA_ARN = addCommandUserLambda.functionArn;

const addCommandUserAsynLambda  = new lambda.Function(this, 'addCommandUserAsynLambda', {
  code: lambda.Code.fromAsset(path.join(__dirname, '../../code/recos')),
  handler: 'add_command_asyn.main_handler',
  runtime: lambda.Runtime.PYTHON_3_8,
  environment: {
    'addCommandUserLambdaArn': COMMAND_LAMBDA_ARN
  }
})

manhcuong-nguyen avatar Dec 14 '21 14:12 manhcuong-nguyen