AWS Lambda Function ( versioning and integration with API Gateway )

Asked

Viewed 220 times

3

Problems with lambda versioning:

  1. I have a lambda function where I use environment variables.
  2. This function is executed by an endpoint through the Gateway API ( aws )
  3. I have 3 stages of the same feature ( Gateway Api ): dev, Hom, Prod
  4. I have to change the lambda environment variable according to the stage that is calling the function.

The problem is that, as all stages call the same lambda function, both stages use the lambda version in producing, in the environment variables I define the connection to the database, I need this connection to change according to the stage that called the function. I tried to versioning the function but I had the problem of not being able to change the environment variable in the version, it is only possible to change in the master.

Follows explanatory images of the problem.

inserir a descrição da imagem aqui

  • Wouldn’t it be the case to use three lambda functions, each with its own defined environment variables? You have the advantage ai to evolve your code without impacting the function running in production

2 answers

1

It is not better to create 3 different planes (one for each environment), and in the Gateway API use the Lambda ARN as the stage variable?

If we analyze it:

dev environment (this is where you will test your code, and it is an environment that you can "break" at will)

In your case, you have the same code running for the 3 environments. If you upload something that breaks the code, you drop it all.

1


By gathering some information obtained here in stackoverflow and in the AWS blog, I was able to solve the problem as follows.

  1. I defined stage variables inserir a descrição da imagem aqui

  2. I created environment variables in my lambda function, specifying the database name of each environment (stage). inserir a descrição da imagem aqui

  3. In the code ( Go ), I check the stage variables, according to the variable modify the name of the database, thus being able to connect in the database of the indicated stage. inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.