내용으로 건너뛰기

Lambda alias as input for ApiGatewayToLambda construct

0

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

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

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개 답변
0
수락된 답변
Function function = (Function) lambdaStack.getAlias().getLambda()
ApiGatewayToLambda integrationSolution = ApiGatewayToLambda.Builder
            .create(this, "ApiGatewayToLambdaPattern")
            .existingLambdaObj(function)
            .build();

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 https://github.com/awslabs/aws-solutions-constructs/blob/main/source/patterns/%40aws-solutions-constructs/aws-apigateway-lambda/lib/index.ts#L32

[2] - Allow Lambda Aliases To Be Used With Constructs #208 https://github.com/awslabs/aws-solutions-constructs/issues/208

[3] - getLambda() https://docs.aws.amazon.com/cdk/api/v2/java/software/amazon/awscdk/services/lambda/Alias.html#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.

답변함 3년 전
전문가
검토됨 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠