aws / aws/aws-sam-cli

Bug: start-api giving error for CDK lambda function and layer in nested stacks - with layer ARN as parameter-override

Open
#4,457 6 comments 0 reactions 0 assignees View on GitHub
type/feature
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:
I am getting an error when trying to use 'sam local start-api' on a template containing the API Gateway and generated by 'cdk synth'. The API Gateway is in the main stack. The lambda function is in a nested stack. The lambda function has a layer that is also in a nested stack (parallel to the lambda function stack). The ARN for the lambda layer in the AWS account is being passed as a --parameter-override.

However, I am having success running 'sam local invoke' and specifying the nested stack template with the lambda function.

Here is the CDK code for the stacks:

```
import * as apigw from '@aws-cdk/aws-apigateway';
import * as acm from '@aws-cdk/aws-certificatemanager';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
import * as rds from '@aws-cdk/aws-rds';
import * as s3 from '@aws-cdk/aws-s3';
import * as assets from '@aws-cdk/aws-s3-assets';
import * as sm from '@aws-cdk/aws-secretsmanager';
import * as sqs from '@aws-cdk/aws-sqs';
import * as ssm from '@aws-cdk/aws-ssm';
import * as cdk from '@aws-cdk/core';
import * as path from 'path';
import { Environment } from '../../common/enum';

import { IEnvironmentConfig } from '../../config/environment-config';

interface LambdaApiGatewayStackProps extends cdk.StackProps {
envConfig: IEnvironmentConfig,
windowsLoginUser?: string
}

export class LambdaApiGatewayStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: LambdaApiGatewayStackProps) {
super(scope, id, props);

const lambdaExecutionRoleImport = iam.Role.fromRoleArn(this, 'LambdaExecRoleImport', cdk.Fn.importValue(props.envConfig.cfnOutputNames.lambdaExecutionRoleArn));
const lambdaExecutionRole = this.grantPermissionsOnLambdaExecutionRole(lambdaExecutionRoleImport, props);

// START API GATEWAY
const restApi = new apigw.RestApi(this, 'RestApi', {
deploy: false,
endpointConfiguration: {
types: [apigw.EndpointType.REGIONAL]
},
defaultCorsPreflightOptions: {
allowOrigins: apigw.Cors.ALL_ORIGINS,
allowMethods: apigw.Cors.ALL_METHODS
},
binaryMediaTypes: ['multipart/form-data']
});
var psCertificateArnAPIGateway = null;
var certificate = null;
if (props?.envConfig.environment != Environment.Predev && props?.envConfig.environment != Environment.PredevSpike) {
psCertificateArnAPIGateway = ssm.StringParameter.valueForStringParameter(this, 'ps_certificateArnAPIGateway');
certificate = acm.Certificate.fromCertificateArn(this, 'APIGatewayCertifiate', (psCertificateArnAPIGateway as string));
const domainName = new apigw.DomainName(this, 'APIGatewayDomainName',
{
domainName: props.envConfig.domain.name,
certificate: certificate,
endpointType: apigw.EndpointType.REGIONAL,
securityPolicy: apigw.SecurityPolicy.TLS_1_2

});

const basePathMapping = domainName.addBasePathMapping(restApi, { basePath: 'prod', stage: restApi.deploymentStage });
var cfnBasePathMapping = basePathMapping.node.defaultChild as apigw.CfnBasePathMapping;

cfnBasePathMapping.addPropertyOverride('Stage', 'prod');
}

restApi.root.addMethod('ANY');
// END API GATEWAY

const lambdaLayerStack = new LambdaLayerStack(this, 'LambdaLayer-LambdaApiGatewayStack', {
envConfig: props.envConfig,
});

// Authorizer - For whatever reason, trying to define this in a nested stack leads to a template with a circular dependency.
const authorizerFn = new lambda.Function(this, 'TokenAuthorizerFn', {
runtime: lambda.Runtime.NODEJS_14_X,
memorySize: props.envConfig.lambda.memorySize,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(this.node.tryGetContext("backend_path") + "/authorizers/JS/jwt-rsa-aws-custom-authorizer")),
tracing: props.envConfig.lambda.xRayTracing,
environment: {
"JWKS_URI": props.envConfig.azureActiveDirectoryAppRegistration.jwksURI,
"AUDIENCE": props.envConfig.azureActiveDirectoryAppRegistration.applicationID,
"TOKEN_ISSUER": props.envConfig.azureActiveDirectoryAppRegistration.tokenIssuer,
},
timeout: cdk.Duration.minutes(2),
});

const lambdaAuthorizer = new apigw.TokenAuthorizer(this, 'TokenAuthorizer', {
handler: authorizerFn,
resultsCacheTtl: cdk.Duration.millis(0),
});

const lambdaFunctionStack = new LambdaFunctionStack(this, 'LambdaFunctionStack', {
restApiId: restApi.restApiId,
rootResourceId: restApi.restApiRootResourceId,
lambdaLayer: lambdaLayerStack.lambdaLayer,
lambdaAuthorizer: lambdaAuthorizer,
lambdaExecutionRole,
envConfig: props.envConfig,
windowsLoginUser: props.windowsLoginUser,
});
lambdaFunctionStack.addDependency(lambdaLayerStack);
}

private grantPermissionsOnLambdaExecutionRole(lambdaExecutionRole: iam.IRole, props: LambdaApiGatewayStackProps): iam.IRole {
const lambdaExecutionRoleExport = iam.Role.fromRoleArn(this, 'LambdaExecRole', lambdaExecutionRole.roleArn);

// Code omitted - a lambda execution role is created and permissions to various AWS services are added to its policy.
...

return lambdaExecutionRoleExport;
}

static setupLambdaIntegration(scope: cdk.Construct, props: LambdaAliasScalingProps): LambdaIntegrationOutput {
var lambdaIntegration: apigw.LambdaIntegration;
lambdaIntegration = new apigw.LambdaIntegration(props.lambdaFunction);
return { lambdaIntegration };
}
}

interface LambdaIntegrationOutput {
lambdaIntegration: apigw.LambdaIntegration,
}

interface LayerNestedStackProps extends cdk.NestedStackProps {
envConfig: IEnvironmentConfig;
}

class LambdaLayerStack extends cdk.NestedStack {
readonly lambdaLayerAsset: assets.Asset;
readonly lambdaLayer: lambda.LayerVersion;

constructor(scope: cdk.Construct, id: string, props: LayerNestedStackProps) {
super(scope, id, props);

this.lambdaLayerAsset = new assets.Asset(
this,
`lambdalayer`,
{
path: path.join(this.node.tryGetContext("lambda_layers_path") + "/layer-pkg/target/layer-pkg-1.0.jar"),
}
);

const codebucket = s3.Bucket.fromBucketName(this, "codebucket", this.lambdaLayerAsset.s3BucketName);

this.lambdaLayer = new lambda.LayerVersion(this, 'cdk-layer', {
code: lambda.Code.fromBucket(codebucket, this.lambdaLayerAsset.s3ObjectKey),
compatibleRuntimes: [lambda.Runtime.JAVA_11],
description: 'Layer with common code for Lambda Handlers',
});

}
}

interface ResourceNestedStackProps extends cdk.NestedStackProps {
readonly restApiId: string;
readonly rootResourceId: string;
readonly lambdaLayer: lambda.LayerVersion;
readonly lambdaAuthorizer: apigw.RequestAuthorizer;
readonly lambdaExecutionRole: iam.IRole;
envConfig: IEnvironmentConfig;
windowsLoginUser?: string;
}

class LambdaFunctionStack extends cdk.NestedStack {
public readonly methods: apigw.Method[] = [];
readonly lambdaLayerAsset: assets.Asset;

constructor(scope: cdk.Construct, id: string, props: ResourceNestedStackProps) {
super(scope, id, props);

const useDebugLogLevel = new ssm.StringParameter(this, props.envConfig.ssmStringParameterNames.lambdaUseDebugLogLevel, {
stringValue: props.envConfig.ssmStringParameterValues.lambdaUseDebugLogLevel,
parameterName: props.envConfig.ssmStringParameterNames.lambdaUseDebugLogLevel,
description: "Boolean to manually toggle lambda debug level logging",
tier: ssm.ParameterTier.STANDARD,
type: ssm.ParameterType.STRING
});

const api = apigw.RestApi.fromRestApiAttributes(this, 'RestApi', {
restApiId: props.restApiId,
rootResourceId: props.rootResourceId,
});

const DefaultVpc = ec2.Vpc.fromLookup(this, 'ImportVPC', { tags: { AppID: props.envConfig.networking.tag } })
const securityGroup = ec2.SecurityGroup.fromSecurityGroupId(
this,
'Lambda Security Group',
props.envConfig.securityGroup.lambda,
);

const rdsDriverClass = ssm.StringParameter.fromStringParameterAttributes(this, 'rdsDriverClass', {
parameterName: props.envConfig.ssmStringParameterNames.rdsLambdaDriverClass,
}).stringValue;
const rdsLambdaConnectionString = ssm.StringParameter.fromStringParameterAttributes(this, 'rdsLambdaConnectionString', {
parameterName: props.envConfig.ssmStringParameterNames.rdsLambdaConnectionString,
}).stringValue;
const rdsLambdaUserName = ssm.StringParameter.fromStringParameterAttributes(this, 'rdsLambdaUserName', {
parameterName: props.envConfig.ssmStringParameterNames.rdsLambdaUserName,
}).stringValue;
const rdsPasswordSecretArn = ssm.StringParameter.fromStringParameterAttributes(this, 'rdsPasswordSecretArn', {
parameterName: props.envConfig.ssmStringParameterNames.rdsLambdaPasswordSecretArn,
}).stringValue;

const apiroot = api.root.addResource('api');
const mockIntegration = new apigw.MockIntegration({
integrationResponses: [{
statusCode: '200',
}],
passthroughBehavior: apigw.PassthroughBehavior.NEVER,
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
});

// Admin Function
const adminHandlerFunction = new lambda.Function(this, "adminHandlerFunction", {
runtime: lambda.Runtime.JAVA_11,
code: lambda.Code.fromAsset(this.node.tryGetContext("lambda_functions_path") + "/admin-handler/target/admin-handler-1.0.jar"),
memorySize: props.envConfig.lambda.memorySize,
securityGroups: [securityGroup],
vpc: DefaultVpc,
handler: "handler.AdminHandler::handleRequest",
role: props.lambdaExecutionRole,
layers: [props.lambdaLayer],
tracing: props.envConfig.lambda.xRayTracing,
timeout: cdk.Duration.minutes(2),
environment: {
dbDriverClassName: rdsDriverClass,
dbUrl: rdsLambdaConnectionString,
dbUsername: rdsLambdaUserName,
dbPasswordSecretArn: rdsPasswordSecretArn,
useDebugLogLevel: useDebugLogLevel.stringValue,
}
});

const adminHandlerLambdaIntegrationOutput = LambdaApiGatewayStack.setupLambdaIntegration(this, {
lambdaFunction: adminHandlerFunction,
aliasId: 'adminHandlerFunctionAlias',
minCapacity: props.envConfig.lambda.minProvisionedConcurrency, maxCapacity: props.envConfig.lambda.maxProvisionedConcurrency,
});

this.addMethod(apiroot, 'getLoginUser', props.lambdaAuthorizer, [
{ httpMethod: 'GET', integration: adminHandlerLambdaIntegrationOutput.lambdaIntegration },
{ httpMethod: 'OPTIONS', integration: mockIntegration },
]);

}

private addMethod(apiRoot: apigw.Resource, pathPart: string, authorizer: apigw.RequestAuthorizer, httpMethodIntegrations: HttpMethodIntegration[]) {
const resource = apiRoot.addResource(pathPart);
var method = null;
(httpMethodIntegrations ?? []).forEach((httpMethodIntegration) => {
method = resource.addMethod(httpMethodIntegration.httpMethod, httpMethodIntegration.integration, {
authorizer,
});
this.methods.push(method);
});
}

}

export interface LambdaAliasScalingProps {
lambdaFunction: lambda.Function,
aliasId: string,
minCapacity: number,
maxCapacity: number,
}
export interface HttpMethodIntegration {
httpMethod: string,
integration: apigw.Integration,
}
```

### Steps to reproduce:

1. run 'cdk synth'
2. build the lambda function and layer JARs
3. run 'cdk synth && cdk deploy -a cdk.out/assembly-Spike-App/ --all'
4. run
```
sam local start-api --parameter-overrides "ParameterKey=referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef,ParameterValue=arn:aws:lambda:us-west-2:634226448102:layer:ecabcdklayerCFC40AB1:1450" -t /home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/SpikeAppLambdaApiGatewayStackgdengCEFF345E.template.json -n /home/gdeng/app-dev/repo/source/locals.json --region us-west-2'
```
6. send a GET request to http://127.0.0.1:3000/api/getLoginUser

In contrast, 'sam local invoke' on the nested stack with the lambda function will work:
```
sam local invoke adminHandlerFunction868947F4 --parameter-overrides "ParameterKey=referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef,ParameterValue=arn:aws:lambda:us-west-2:634226448102:layer:ecabcdklayerCFC40AB1:1450" -t /home/gdeng/app-dev/e-cabinet-repo/e-cabinet-source/cdk.out/assembly-Spike-App/SpikeAppLambdaApiGatewayStackgdengLambdaFunctionStack1AEFD0A4.nested.template.json -e /home/gdeng/app-dev/e-cabinet-repo/e-cabinet-source/events/adminHandlerEvent.json -n /home/gdeng/app-dev/e-cabinet-repo/e-cabinet-source/locals.json --region us-west-2
```

### Observed result:

```
sam local start-api --parameter-overrides "ParameterKey=referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef,ParameterValue=arn:aws:lambda:us-west-2:634226448102:layer:ecabcdklayerCFC40AB1:1450" -t /home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/SpikeAppLambdaApiGatewayStackgdengCEFF345E.template.json -n /home/gdeng/app-dev/repo/source/locals.json --region us-west-2 --debug
2022-12-01 15:30:21,557 | Config file location: /home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/samconfig.toml
2022-12-01 15:30:21,557 | Config file '/home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/samconfig.toml' does not exist
2022-12-01 15:30:21,579 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-12-01 15:30:21,579 | Using config file: samconfig.toml, config environment: default
2022-12-01 15:30:21,579 | Expand command line arguments to:
2022-12-01 15:30:21,579 | --template_file=/home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/SpikeAppLambdaApiGatewayStackgdengCEFF345E.template.json --parameter_overrides={'referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef': 'arn:aws:lambda:us-west-2:634226448102:layer:ecabcdklayerCFC40AB1:1450'} --env_vars=/home/gdeng/app-dev/repo/source/locals.json --host=127.0.0.1 --port=3000 --static_dir=public --layer_cache_basedir=/home/gdeng/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2022-12-01 15:30:21,651 | local start-api command is called
2022-12-01 15:30:21,651 | Collected default values for parameters: {'rdsPasswordSecretArnParameter': 'ps_lambda_rdsPasswordSecretArn-gdeng-spike', 'openSearchPwdSecretArnParameter': 'ps_os_app_user_secret_complete_arn', 'BootstrapVersion': '/cdk-bootstrap/ecab/version'}
2022-12-01 15:30:21,666 | CDK Path for resource LambdaExecRolePolicyFE83EEC0 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaExecRole', 'Policy', 'Resource']
2022-12-01 15:30:21,666 | CDK Path for resource RestApi0C43BF4B is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Resource']
2022-12-01 15:30:21,666 | CDK Path for resource RestApiCloudWatchRoleE3ED6605 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'CloudWatchRole', 'Resource']
2022-12-01 15:30:21,666 | CDK Path for resource RestApiAccount7C83CF5A is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Account']
2022-12-01 15:30:21,666 | CDK Path for resource RestApiOPTIONS6AA64D2D is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Default', 'OPTIONS', 'Resource']
2022-12-01 15:30:21,666 | CDK Path for resource RestApiANYA7C1DC94 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Default', 'ANY', 'Resource']
2022-12-01 15:30:21,666 | CDK Path for resource LambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource1DAB6992 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaLayer-LambdaApiGatewayStack.NestedStack', 'LambdaLayer-LambdaApiGatewayStack.NestedStackResource']
2022-12-01 15:30:21,666 | CDK Path for resource pslambdaauthorizerUseDebugLogLevelgdengspike11A4203C is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'ps_lambda_authorizerUseDebugLogLevel-gdeng-spike', 'Resource']
2022-12-01 15:30:21,667 | CDK Path for resource TokenAuthorizerFnServiceRoleC4BD3DE8 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizerFn', 'ServiceRole', 'Resource']
2022-12-01 15:30:21,667 | CDK Path for resource TokenAuthorizerFn201D8B13 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizerFn', 'Resource']
2022-12-01 15:30:21,667 | CDK Path for resource TokenAuthorizerFnSpikeAppLambdaApiGatewayStackgdengTokenAuthorizer91F1FF33PermissionsAD65A8EF is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizerFn', 'SpikeAppLambdaApiGatewayStackgdengTokenAuthorizer91F1FF33:Permissions']
2022-12-01 15:30:21,667 | CDK Path for resource TokenAuthorizer82AECDDC is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizer', 'Resource']
2022-12-01 15:30:21,667 | CDK Path for resource LambdaFunctionStackNestedStackLambdaFunctionStackNestedStackResource333996F6 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack.NestedStack', 'LambdaFunctionStack.NestedStackResource']
2022-12-01 15:30:21,667 | CDK Path for resource CDKMetadata is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'CDKMetadata', 'Default']
2022-12-01 15:30:21,669 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'upsertMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,669 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'upsertMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,669 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'bulkUpdateMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,669 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'bulkUpdateMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,669 | Unable to resolve property Roles: [OrderedDict([('Fn::Select', [1, OrderedDict([('Fn::Split', ['/', OrderedDict([('Fn::Select', [5, OrderedDict([('Fn::Split', [':', OrderedDict([('Fn::ImportValue', 'lambdaExecutionRoleArn-gdeng-spike')])])])])])])])])])]. Leaving as is.
2022-12-01 15:30:21,670 | Unable to resolve property DEBUG: OrderedDict([('Fn::GetAtt', ['pslambdaauthorizerUseDebugLogLevelgdengspike11A4203C', 'Value'])]). Leaving as is.
2022-12-01 15:30:21,670 | Unable to resolve property referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef: OrderedDict([('Fn::GetAtt', ['LambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource1DAB6992', 'Outputs.SpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef'])]). Leaving as is.
2022-12-01 15:30:21,672 | 2 stacks found in the template
2022-12-01 15:30:21,672 | No Parameters detected in the template
2022-12-01 15:30:21,683 | CDK Path for resource ecabcdklayerCFC40AB1 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaLayer-LambdaApiGatewayStack', 'cdk-layer', 'Resource']
2022-12-01 15:30:21,683 | CDK Path for resource CDKMetadata is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaLayer-LambdaApiGatewayStack', 'CDKMetadata', 'Default']
2022-12-01 15:30:21,683 | 0 stacks found in the template
2022-12-01 15:30:21,683 | Collected default values for parameters: {'rdsDriverClassParameter': 'ps_lambda_rdsDriverClass-gdeng-spike', 'rdsLambdaConnectionStringParameter': 'ps_lambda_rdsConnectionString-gdeng-spike', 'rdsLambdaUserNameParameter': 'ps_lambda_rdsUserName-gdeng-spike', 'rdsPasswordSecretArnParameter': 'ps_lambda_rdsPasswordSecretArn-gdeng-spike'}
2022-12-01 15:30:21,696 | CDK Path for resource pslambdauseDebugLogLevelgdengspike021B0CC8 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'ps_lambda_useDebugLogLevel-gdeng-spike', 'Resource']
2022-12-01 15:30:21,696 | CDK Path for resource RestApiapiC55947A1 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'Resource']
2022-12-01 15:30:21,696 | CDK Path for resource RestApiapigetLoginUser9EA91BE2 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'Resource']
2022-12-01 15:30:21,696 | CDK Path for resource RestApiapigetLoginUserGETApiPermissionSpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277GETapigetLoginUserBDE7464A is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'GET', 'ApiPermission.SpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277.GET..api.getLoginUser']
2022-12-01 15:30:21,696 | CDK Path for resource RestApiapigetLoginUserGETApiPermissionTestSpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277GETapigetLoginUserFF217F2D is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'GET', 'ApiPermission.Test.SpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277.GET..api.getLoginUser']
2022-12-01 15:30:21,696 | CDK Path for resource RestApiapigetLoginUserGET8438924F is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'GET', 'Resource']
2022-12-01 15:30:21,696 | CDK Path for resource RestApiapigetLoginUserOPTIONS2682EFFD is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'OPTIONS', 'Resource']
2022-12-01 15:30:21,696 | CDK Path for resource adminHandlerFunction868947F4 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'adminHandlerFunction', 'Resource']
2022-12-01 15:30:21,696 | CDK Path for resource CDKMetadata is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'CDKMetadata', 'Default']
2022-12-01 15:30:21,697 | Unable to resolve property Role: OrderedDict([('Fn::ImportValue', 'lambdaExecutionRoleArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,697 | Unable to resolve property useDebugLogLevel: OrderedDict([('Fn::GetAtt', ['pslambdauseDebugLogLevelgdengspike021B0CC8', 'Value'])]). Leaving as is.
2022-12-01 15:30:21,697 | 0 stacks found in the template
2022-12-01 15:30:21,697 | Collected default values for parameters: {'rdsPasswordSecretArnParameter': 'ps_lambda_rdsPasswordSecretArn-gdeng-spike', 'openSearchPwdSecretArnParameter': 'ps_os_app_user_secret_complete_arn', 'BootstrapVersion': '/cdk-bootstrap/ecab/version'}
2022-12-01 15:30:21,712 | CDK Path for resource LambdaExecRolePolicyFE83EEC0 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaExecRole', 'Policy', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource RestApi0C43BF4B is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource RestApiCloudWatchRoleE3ED6605 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'CloudWatchRole', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource RestApiAccount7C83CF5A is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Account']
2022-12-01 15:30:21,712 | CDK Path for resource RestApiOPTIONS6AA64D2D is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Default', 'OPTIONS', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource RestApiANYA7C1DC94 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'RestApi', 'Default', 'ANY', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource LambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource1DAB6992 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaLayer-LambdaApiGatewayStack.NestedStack', 'LambdaLayer-LambdaApiGatewayStack.NestedStackResource']
2022-12-01 15:30:21,712 | CDK Path for resource pslambdaauthorizerUseDebugLogLevelgdengspike11A4203C is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'ps_lambda_authorizerUseDebugLogLevel-gdeng-spike', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource TokenAuthorizerFnServiceRoleC4BD3DE8 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizerFn', 'ServiceRole', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource TokenAuthorizerFn201D8B13 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizerFn', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource TokenAuthorizerFnSpikeAppLambdaApiGatewayStackgdengTokenAuthorizer91F1FF33PermissionsAD65A8EF is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizerFn', 'SpikeAppLambdaApiGatewayStackgdengTokenAuthorizer91F1FF33:Permissions']
2022-12-01 15:30:21,712 | CDK Path for resource TokenAuthorizer82AECDDC is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'TokenAuthorizer', 'Resource']
2022-12-01 15:30:21,712 | CDK Path for resource LambdaFunctionStackNestedStackLambdaFunctionStackNestedStackResource333996F6 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack.NestedStack', 'LambdaFunctionStack.NestedStackResource']
2022-12-01 15:30:21,712 | CDK Path for resource CDKMetadata is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'CDKMetadata', 'Default']
2022-12-01 15:30:21,714 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'upsertMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,714 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'upsertMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,714 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'bulkUpdateMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,714 | Unable to resolve property Resource: OrderedDict([('Fn::ImportValue', 'bulkUpdateMessageSqsQueueArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,714 | Unable to resolve property Roles: [OrderedDict([('Fn::Select', [1, OrderedDict([('Fn::Split', ['/', OrderedDict([('Fn::Select', [5, OrderedDict([('Fn::Split', [':', OrderedDict([('Fn::ImportValue', 'lambdaExecutionRoleArn-gdeng-spike')])])])])])])])])])]. Leaving as is.
2022-12-01 15:30:21,714 | Unable to resolve property DEBUG: OrderedDict([('Fn::GetAtt', ['pslambdaauthorizerUseDebugLogLevelgdengspike11A4203C', 'Value'])]). Leaving as is.
2022-12-01 15:30:21,715 | Unable to resolve property referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef: OrderedDict([('Fn::GetAtt', ['LambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource1DAB6992', 'Outputs.SpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef'])]). Leaving as is.
2022-12-01 15:30:21,715 | 14 resources found in the stack
2022-12-01 15:30:21,716 | No Parameters detected in the template
2022-12-01 15:30:21,727 | CDK Path for resource ecabcdklayerCFC40AB1 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaLayer-LambdaApiGatewayStack', 'cdk-layer', 'Resource']
2022-12-01 15:30:21,727 | CDK Path for resource CDKMetadata is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaLayer-LambdaApiGatewayStack', 'CDKMetadata', 'Default']
2022-12-01 15:30:21,727 | 2 resources found in the stack LambdaLayer-LambdaApiGatewayStack
2022-12-01 15:30:21,727 | Collected default values for parameters: {'rdsDriverClassParameter': 'ps_lambda_rdsDriverClass-gdeng-spike', 'rdsLambdaConnectionStringParameter': 'ps_lambda_rdsConnectionString-gdeng-spike', 'rdsLambdaUserNameParameter': 'ps_lambda_rdsUserName-gdeng-spike', 'rdsPasswordSecretArnParameter': 'ps_lambda_rdsPasswordSecretArn-gdeng-spike'}
2022-12-01 15:30:21,741 | CDK Path for resource pslambdauseDebugLogLevelgdengspike021B0CC8 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'ps_lambda_useDebugLogLevel-gdeng-spike', 'Resource']
2022-12-01 15:30:21,741 | CDK Path for resource RestApiapiC55947A1 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'Resource']
2022-12-01 15:30:21,741 | CDK Path for resource RestApiapigetLoginUser9EA91BE2 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'Resource']
2022-12-01 15:30:21,741 | CDK Path for resource RestApiapigetLoginUserGETApiPermissionSpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277GETapigetLoginUserBDE7464A is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'GET', 'ApiPermission.SpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277.GET..api.getLoginUser']
2022-12-01 15:30:21,741 | CDK Path for resource RestApiapigetLoginUserGETApiPermissionTestSpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277GETapigetLoginUserFF217F2D is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'GET', 'ApiPermission.Test.SpikeAppLambdaApiGatewayStackgdengLambdaFunctionStackRestApi8B903277.GET..api.getLoginUser']
2022-12-01 15:30:21,741 | CDK Path for resource RestApiapigetLoginUserGET8438924F is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'GET', 'Resource']
2022-12-01 15:30:21,741 | CDK Path for resource RestApiapigetLoginUserOPTIONS2682EFFD is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'RestApi', 'Default', 'api', 'getLoginUser', 'OPTIONS', 'Resource']
2022-12-01 15:30:21,741 | CDK Path for resource adminHandlerFunction868947F4 is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'adminHandlerFunction', 'Resource']
2022-12-01 15:30:21,741 | CDK Path for resource CDKMetadata is ['Spike-App', 'LambdaApiGatewayStack-gdeng', 'LambdaFunctionStack', 'CDKMetadata', 'Default']
2022-12-01 15:30:21,742 | Unable to resolve property Role: OrderedDict([('Fn::ImportValue', 'lambdaExecutionRoleArn-gdeng-spike')]). Leaving as is.
2022-12-01 15:30:21,742 | Unable to resolve property useDebugLogLevel: OrderedDict([('Fn::GetAtt', ['pslambdauseDebugLogLevelgdengspike021B0CC8', 'Value'])]). Leaving as is.
2022-12-01 15:30:21,742 | 9 resources found in the stack LambdaFunctionStack
2022-12-01 15:30:21,742 | Found Lambda function with name='TokenAuthorizerFn201D8B13' and CodeUri='../asset.61af0fc7eb5a561e51f7affeeef6349eb9a2e45ffff0eee044147b3b5fed72f2'
2022-12-01 15:30:21,742 | --base-dir is not presented, adjusting uri ../asset.61af0fc7eb5a561e51f7affeeef6349eb9a2e45ffff0eee044147b3b5fed72f2 relative to /home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/SpikeAppLambdaApiGatewayStackgdengCEFF345E.template.json
2022-12-01 15:30:21,743 | Found Lambda function with name='adminHandlerFunction868947F4' and CodeUri='../asset.65c87806e8a12bbfe0f35a3f09b678752fd0669f4980be80cfcf3420829836d7.jar'
2022-12-01 15:30:21,743 | --base-dir is not presented, adjusting uri ../asset.65c87806e8a12bbfe0f35a3f09b678752fd0669f4980be80cfcf3420829836d7.jar relative to /home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App/SpikeAppLambdaApiGatewayStackgdengLambdaFunctionStack1AEFD0A4.nested.template.json
2022-12-01 15:30:21,746 | Skipping resource 'RestApi0C43BF4B'. Swagger document not found in Body and BodyS3Location
2022-12-01 15:30:21,746 | Extracted Function ARN: None
2022-12-01 15:30:21,746 | Extracted Function ARN: None
2022-12-01 15:30:21,747 | Extracted Function ARN: arn:aws:lambda:us-west-2:123456789012:function:adminHandlerFunction868947F4
2022-12-01 15:30:21,747 | Extracted Function ARN: None
2022-12-01 15:30:21,747 | 3 APIs found in the template
2022-12-01 15:30:21,752 | Mounting None at http://127.0.0.1:3000/ [DELETE, GET, HEAD, OPTIONS, OPTIONS, PATCH, POST, PUT]
2022-12-01 15:30:21,752 | Mounting adminHandlerFunction868947F4 at http://127.0.0.1:3000/api/getLoginUser [GET, OPTIONS]
2022-12-01 15:30:21,752 | Mounting None at http://127.0.0.1:3000/api/getLoginUser [OPTIONS]
2022-12-01 15:30:21,752 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2022-12-01 15:30:21,752 | Localhost server is starting up. Multi-threading = True
2022-12-01 15:30:21 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2022-12-01 15:30:25,438 | Constructed String representation of Event to invoke Lambda. Event: {"body": null, "headers": {"Accept": "*/*", "Accept-Encoding": "gzip, deflate, br", "Authorization": "Bearer ", "Connection": "keep-alive", "Host": "127.0.0.1:3000", "Msgid": "sfa", "Opr": "112", "Postman-Token": "6978b446-7cf7-4b64-8a30-62c3b1214120", "Repoid": "0", "Sysid": "vxcab-ui", "User-Agent": "PostmanRuntime/7.29.2", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "GET", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["*/*"], "Accept-Encoding": ["gzip, deflate, br"], "Authorization": ["Bearer "], "Connection": ["keep-alive"], "Host": ["127.0.0.1:3000"], "Msgid": ["sfa"], "Opr": ["112"], "Postman-Token": ["6978b446-7cf7-4b64-8a30-62c3b1214120"], "Repoid": ["0"], "Sysid": ["vxcab-ui"], "User-Agent": ["PostmanRuntime/7.29.2"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/api/getLoginUser", "pathParameters": null, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "127.0.0.1:3000", "extendedRequestId": null, "httpMethod": "GET", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "127.0.0.1", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/api/getLoginUser", "protocol": "HTTP/1.1", "requestId": "255aa0f0-89be-4db5-bc7c-7e630c85cc45", "requestTime": "01/Dec/2022:23:30:21 +0000", "requestTimeEpoch": 1669937421, "resourceId": "123456", "resourcePath": "/api/getLoginUser", "stage": null}, "resource": "/api/getLoginUser", "stageVariables": null, "version": "1.0"}
2022-12-01 15:30:25,438 | Found one Lambda function with name 'adminHandlerFunction868947F4'
2022-12-01 15:30:25,438 | Invoking handler.AdminHandler::handleRequest (java11)
2022-12-01 15:30:25,438 | Environment variables data found for specific function in standard format
2022-12-01 15:30:25,438 | Loading AWS credentials from session with profile 'None'
2022-12-01 15:30:25,453 | Resolving code path. Cwd=/home/gdeng/app-dev/repo/source/cdk.out/assembly-Spike-App, CodeUri=/home/gdeng/app-dev/repo/source/cdk.out/asset.65c87806e8a12bbfe0f35a3f09b678752fd0669f4980be80cfcf3420829836d7.jar
2022-12-01 15:30:25,453 | Resolved absolute path to code is /home/gdeng/app-dev/repo/source/cdk.out/asset.65c87806e8a12bbfe0f35a3f09b678752fd0669f4980be80cfcf3420829836d7.jar
2022-12-01 15:30:25,454 | Decompressing /home/gdeng/app-dev/repo/source/cdk.out/asset.65c87806e8a12bbfe0f35a3f09b678752fd0669f4980be80cfcf3420829836d7.jar
2022-12-01 15:30:25,458 | File META-INF/ in zipfile does not have permission information
2022-12-01 15:30:25,459 | File META-INF/MANIFEST.MF in zipfile does not have permission information
2022-12-01 15:30:25,459 | File application.yml in zipfile does not have permission information

...

2022-12-01 15:30:25,724 | File org/hamcrest/internal/SelfDescribingValueIterator.class in zipfile does not have permission information
2022-12-01 15:30:25,725 | Cleaning all decompressed code dirs
2022-12-01 15:30:25,755 | Exception on /api/getLoginUser [GET]
Traceback (most recent call last):
File "samcli/lib/providers/provider.py", line 277, in _compute_layer_name
ValueError: not enough values to unpack (expected 3, got 1)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "flask/app.py", line 2073, in wsgi_app
File "flask/app.py", line 1518, in full_dispatch_request
File "flask/app.py", line 1516, in full_dispatch_request
File "flask/app.py", line 1502, in dispatch_request
File "samcli/local/apigw/local_apigw_service.py", line 361, in _request_handler
File "samcli/commands/local/lib/local_lambda.py", line 144, in invoke
File "samcli/lib/telemetry/metric.py", line 277, in wrapped_func
File "samcli/local/lambdafn/runtime.py", line 177, in invoke
File "samcli/local/lambdafn/runtime.py", line 88, in create
File "samcli/local/docker/lambda_container.py", line 94, in __init__
File "samcli/local/docker/lambda_container.py", line 236, in _get_image
File "samcli/local/docker/lambda_image.py", line 137, in build
File "samcli/local/layers/layer_downloader.py", line 77, in download_all
File "samcli/local/layers/layer_downloader.py", line 102, in download
File "samcli/lib/providers/provider.py", line 332, in name
File "samcli/lib/providers/provider.py", line 279, in _compute_layer_name
samcli.commands.local.cli_common.user_exceptions.InvalidLayerVersionArn: referencetoSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackNestedStackLambdaLayerLambdaApiGatewayStackNestedStackResource23220441OutputsSpikeAppLambdaApiGatewayStackgdengLambdaLayerLambdaApiGatewayStackecabcdklayer84D5FD0CRef is an Invalid Layer Arn.
2022-12-01 15:30:25 127.0.0.1 - - [01/Dec/2022 15:30:25] "GET /api/getLoginUser HTTP/1.1" 502 -
```

### Expected result:

An HTTP response with status 200

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: Ubuntu 20.04.3 LTS (Windows Subsystem for Linux)
8. `sam --version`: 1.65.0
9. AWS region: us-west-2

`Add --debug flag to command you are running`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.