Hi there, I'm new with Pulumi, I have been trying to deploy an API gateway (HTTP) with openAPI, but ...
c
Hi there, I'm new with Pulumi, I have been trying to deploy an API gateway (HTTP) with openAPI, but running into some issue
Copy code
// Return aws.lambda.Function
const testingHandler = createLambda(
  "testingHandler",
  config,
  {
    handler: "testingHandler.handler",
  },
);


const openApiSpec = {
  openapi: "3.0.1",
  info: {
    title: "Lambda API testing",
    version: "1.0.0",
  },
  paths: {
    "/hello": {
      get: {
        "x-amazon-apigateway-integration": {
          type: "aws_proxy",
          httpMethod: "POST",
          uri: pulumi.interpolate`arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${testingHandler.invokeArn}/invocations`,
          connectionType: "INTERNET",
        },
        responses: {
          "200": {
            description: "A simple hello world response",
          },
        },
      },
    },
  },
};

// API Gateway Rest API
const api = new aws.apigatewayv2.Api("apiTesting", {
  protocolType: "HTTP",
  body: JSON.stringify(openApiSpec),
});

// Create a stage for the API
new aws.apigatewayv2.Stage("stageTesting", {
  apiId: api.id,
  name: "v1",
  autoDeploy: true,
});
But when I go to the API gateway in AWS console, the stage was not able to deploy
Unable to deploy API because no routes exist in this API
When I do export my OpenAPI spec from the API gateway, somehow the x-amazon-apigateway-integration got removed Does anyone have any idea what I could be missing?
m
I think the problem is that you cannot use
JSON.stringify
when there is a Pulumi output in the JSON, because the output's value is not yet known at the point in time the code is executed. Pulumi provides a utility function
pulumi.jsonStringify
for that purpose, see https://www.pulumi.com/docs/concepts/inputs-outputs/apply/#converting-json-objects-to-strings If you replace
JSON.stringify
with
pulumi.jsonStringify
you'll pass the proper API spec to the API gateway resource. To inspect your generated API spec, you can export it as a stack output.