Lambda alias as input for ApiGatewayToLambda construct


Background: We are using CDK to create a infrastructure. We use rest api gateway and lambda and integrate them together. We use "" construct for this integration. The sample code below.

apiGatewayToLambda = ApiGatewayToLambda.Builder
            .create(this, stageId + names.componentName + "RestApi")
                    "proxy" to false,
                    "restApiName" to "${waveId}${stageId}${names.componentName}RestApi",
                    "deployOptions" to deployOptions

Problem: We want to provision the lambda since the we are getting "504 - gateway timeout" from API gateway. On investigation we found that the lambda is getting timeout due to cold start.

Blocker: The lambda provisioning can be done only to lambda alias. When we analyze the ApiGatewayToLambda , it does n't accept the lambda alias as input.

How do we go about it ? Are there any workaround ? Can some one from support help me with the path forward ? Some java cdk code samples will be helpful.

1 Answer
Accepted Answer
Function function = (Function) lambdaStack.getAlias().getLambda()
ApiGatewayToLambda integrationSolution = ApiGatewayToLambda.Builder
            .create(this, "ApiGatewayToLambdaPattern")

Kindly notice how the IFunction interface is extracted from the Alias using the getLambda() method, which I then need to cast into a Function object.

[1] - existingLambdaObj source code

[2] - Allow Lambda Aliases To Be Used With Constructs #208

[3] - getLambda()

Solved this issue with the help of AWS Support, sharing here to make the solution available in this public forum, I hope it helps others.

answered a year ago
profile picture
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions