https://pulumi.com logo
Title
s

shy-bird-55689

03/29/2021, 11:43 PM
Hey, i'm probably missing something really simple but i'm getting the following when trying to deploy an api gateway backed by lambda
error: 1 error occurred:
    	* Error creating API Gateway Deployment: BadRequestException: The REST API doesn't contain any methods
(using python) i'm specifying an OpenAPI spec for the body of
aws.apigateway.RestApi
which has routes and methods configured. Not sure what i'm maybe missing somewhere, new to Pulumi (coming from Serverless Framework)
l

little-cartoon-10569

03/29/2021, 11:44 PM
Are you using the aws or awsx package?
s

shy-bird-55689

03/29/2021, 11:47 PM
aws Crosswalk isn't available for python is it?
l

little-cartoon-10569

03/29/2021, 11:48 PM
There is smidge of support for it, but I've just checked and it doesn't include apigateway..
The error is in creating the Deployment. How are you providing the RestApi to the Deployment? Can you share a little code?
s

shy-bird-55689

03/29/2021, 11:54 PM
api_gateway = apigateway.RestApi(
    resource_name='api-gateway',
    body="""swagger: "2.0"
info:
  version: "2021-03-29T15:07:58Z"
  title: "marv"
basePath: "/dev"
schemes:
- "https"
paths:
  /test:
    post:
      responses: {}
      x-amazon-apigateway-integration:
        uri: "REDACTED"
        httpMethod: "POST"
        passthroughBehavior: "when_no_match"
        type: "aws_proxy"""
)

api_gateway_deployment = apigateway.Deployment(
    resource_name='api-gateway-deployment',
    rest_api=api_gateway.id,
    opts=pulumi.ResourceOptions(depends_on=[api_gateway])
)

api_gateway_stage = apigateway.Stage(
    resource_name='marv-api-gateway-stage',
    stage_name='dev',
    rest_api=api_gateway.id,
    deployment=api_gateway_deployment.id
)
l

little-cartoon-10569

03/30/2021, 12:31 AM
Sorry got called afk. Just checking, is there a typo or is the line
type: "aws_proxy"""
supposed to have only 3 double-quotes? There's here-doc opener up on the
body
line, and a string opener on the line in question.. seems like there should be 4 double-quotes?
s

shy-bird-55689

03/30/2021, 8:46 AM
4 double quotes throws up an invalid OpenAPI input error when running pulumi up
l

little-cartoon-10569

03/30/2021, 7:41 PM
Then one double-quote to close the body field, and three double-quotes on another line to close the heredoc? As it is now, it looks unbalanced...
s

shy-bird-55689

03/30/2021, 9:00 PM
cheers for the point in the right direction @little-cartoon-10569 It was down to the general formatting of the yaml string even though it was seemingly valid as it wasnt error the spec. Rather than placing the string directly i'm loading separate spec file with pyYAML and dumping it out. so just:
with open(r'api.yaml') as file:
    openapi_spec = yaml.load(file, Loader=yaml.FullLoader)
and then updating the creation of the RestAPI resource
api_gateway = apigateway.RestApi(
    resource_name='api-gateway',
    body=yaml.dump(openapi_spec)
)
l

little-cartoon-10569

03/30/2021, 9:00 PM
That's certainly more readable 🙂
s

shy-bird-55689

03/30/2021, 9:00 PM
🙂