I'm trying to use AWS SAM to deploy a simple API. When the API is simple (that is, does not specify explicitly an API Gateway). the deployment succeeds.
However, the following deployment fails:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sample API
Parameters:
Stage:
Type: String
AllowedValues:
- dev
- sat
- demo
- staging
- prod
Description: Enter dev, sat, demo, staging or prod
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Stage
EndpointConfiguration: PRIVATE
DefinitionBody:
swagger: '2.0'
x-amazon-apigateway-policy:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: "*"
Action: execute-api:Invoke
Resource:
- !Sub arn:aws:execute-api:*:*:*/${Stage}/*
ThumbnailFunction:
Type: 'AWS::Serverless::Function'
Properties:
Runtime: nodejs8.10
Handler: get-config.handler
CodeUri: ./functions
Events:
ThumbnailApi:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /thumbnail
Method: GET
The error message is the following:
The REST API doesn't contain any methods (Service: AmazonApiGateway;
Status Code: 400; Error Code: BadRequestException
Looking on Google, I do find mentions of this error when manually specifying a deployment (here, or here). In my case, the deployment is implicit, hence I assume my issue is different.
The code I'm using is based on a SAM example (here). I'm scratching my head to understand what is wrong with my stack.
Any pointers to a solution?
Just as the error message says, you have not defined any methods in your Swagger. I think your confusion is here:
In my case, the deployment is implicit, hence I assume my issue is different.
SAM does create implicit APIs of type AWS::Serverless::Api from the union of Api events defined on AWS::Serverless::Function resources - but only if they do not refer (via the RestApiId property) to an AWS::Serverless::Api resource that you defined explicitly in the template. And in your case, it does.
Also, you mention that your template is based on the "api_swagger_cors" example SAM template here, but in fact there is a key difference between yours and that example, namely: in the example, a Swagger YAML file is being pulled in from an S3 bucket; whereas in yours, your Swagger is defined inline, but it doesn't define any methods.
For more info:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With