https://pulumi.com logo
#aws
Title
# aws
p

proud-lawyer-63233

01/13/2020, 3:14 PM
I'm setting up a Lambda function with API Gateway. I'd like to use the resulting API url (eg
endpoint.url
) as an environment variable within the Lambda. However, the lambda is created at a point where I don't yet have the API gateway url. How might I get around this?
Copy code
const myLambda = new aws.lambda.Function("my-handler", {
  runtime: aws.lambda.Python3d7Runtime,
  code: new pulumi.asset.FileArchive("my-package.zip"),
  handler: "handler.lambda_handler",
  environment: {
    variables: {
      ENV_VARIABLE_1: 'foo',
    },
  },
})

const endpoint = new awsx.apigateway.API("my-gateway", {
  routes: [{
      path: "/{proxy+}",
      method: "ANY",
      eventHandler: aws.lambda.Function.get("my-lambda", myLambda.id),
  }],
})
w

white-balloon-205

01/13/2020, 5:10 PM
Yes - because the awsx
API
helper creates both the rest api and the routes at once, I don’t believe there is any way to break this cycle currently. You would need to do something like use an additional data store for this - like parameter store or s3 or dynamodb. If you wouldn’t mind opening an issue on this - it’s come up a couple times recently - and would be good to look into ways to enable it more seamlessly.