HTTP API Gateway: Specifying Different Lambda Version per Stage

1

Hello, I'm trying to create multiple stages for the same HTTP API Gateway (corresponding to Test and Production environments) and make the same Routes point to the same Lambda functions (Integrations) but different versions thereof. I'm trying to do this using CDK, but I think it's not yet supported there. However, I cannot even seem to be able to do this using the console. Any ideas?

2 Risposte
4
Risposta accettata

Hello there,

you can accomplish this using stage variables. After deploying your HTTP API, go to one of the stages, edit, and go down to Stage variables.

Add a key (i.e. lambda_function_version) and as value, the version number of the lambda function you prefer.

Go to the Integration details of your API endpoint and in the Integration target section, use the ARN of the lambda function with the variable you setup previously:

arn:aws:lambda:us-east-1:xxxxxxxxxxxx:function:MyDearLambdaFunction:${stageVariables.lambda_function_version}

Repeat the process for other stages of your API.

Remember that Stage variables don't support cross-account Lambda functions.

Here's the documentation with more details. Hope this helps.

profile pictureAWS
con risposta 2 anni fa
  • Thank you very much! Do you confirm that none of the above is (yet) doable using CDK2? Not even the part where I can set the stage variable in the Route Integration?

  • This does not work anymore. It's shown "AWS ARN for integration must contain path or action" on UI. May be a bug? Please help.

0

Sadly this does not work anymore. Whenever you put a stageVariable into integration target (if integration type is "Lambda function") it fails with "1 validation error detected: Value <arn> at 'functionName' failed to satisfy constraint: Member must satisfy regular expression pattern: <regex>"

con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande