-1

I've got a working API Gateway with a hardcoded Lambda integration deployed using terraform. I want to replace the hardcoded Lambda ARN in the integration with a stage variable, which will open the door to canary usage and better flexibility. This seems to be well aligned with the intent of stage variables.

However when I implement I get a circular dependency I can't seem to break. It looks like:

The stage has the stage variable pointing to the Lambda and:

  • Stage needs the deployment ID
  • The Deployment needs the Lambda Integration
  • The Lambda integration needs the stage

And round and round we go

Yet, as noted, this seems exactly what stage variables are for. Dual deploys won't do, need a seamless one pass deployment.

Has anyone solved this issue?

1 Answer 1

0

For others ... the problem appeared to be a circular dependency but was in fact a nuance in how stage variables are defined and accessed.

Turns out that when you set a stage variable with the parameter "lambda_function_name", they actually mean name, not ARN or some other more common designation. Who woulda thunk it.

So you wind up with something like:

resource "aws_api_gateway_stage" "tunes" {
  deployment_id = ...
  variables = {
    "lambda_function_name" = aws_lambda_function.somefunction.function_name
  }

Then you wrap and reference it in the integration like this:

resource "aws_api_gateway_integration" "lambda" {
  rest_api_id =...
  type                    = "AWS_PROXY"
  uri = "arn:aws:apigateway:${var.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${var.region}:${data.aws_caller_identity.current.account_id}:function:$${stageVariables.lambda_function_name}/invocations"
}

Seems to work fine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.