5

I am trying to create a resource /user/devices with GET method for API Gateway using cloudformation template but it is giving me a below error

An error occurred: ApiGatewayRootMethod - Invalid HTTP endpoint specified for URI (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID:xxxxxxxxxx)

Below is my cloudformation template,

AWSTemplateFormatVersion: 2018-11-13
Description: test user

resources:
  Resources:

    UserDeviceApiGateway:
      Type: "AWS::ApiGateway::RestApi"
      Properties:
        Name: "test-user-info"
        Description: "Fetch the user"

    UserResource:
      Type: 'AWS::ApiGateway::Resource'
      Properties:
        ParentId:
          Fn::GetAtt: ["UserDeviceApiGateway","RootResourceId"]
        RestApiId:
          Ref: "UserDeviceApiGateway"
        PathPart: 'user'

    Resource:
      Type: 'AWS::ApiGateway::Resource'
      Properties:
        ParentId:
          Ref: "UserResource"
        RestApiId:
          Ref: "UserDeviceApiGateway"
        PathPart: 'devices'

    ApiGatewayRootMethod:
      Type: "AWS::ApiGateway::Method"
      Properties:
        AuthorizationType: "NONE"
        HttpMethod: "GET"
        Integration:
          IntegrationHttpMethod: "GET"
          Type: "HTTP"
          Uri: Sub
            - "arn:aws:apigateway:arn:aws:lambda:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:xxxxxxxx:function:user-device-lambda/invocations"
        ResourceId:
          Fn::GetAtt: ["UserDeviceApiGateway","RootResourceId"]
        RestApiId:
          Ref: "UserDeviceApiGateway"

    Deployment:
      DependsOn:
        - ApiGatewayRootMethod
      Type: 'AWS::ApiGateway::Deployment'
      Properties:
        RestApiId:
          Ref: "UserDeviceApiGateway"
        StageName: dev
JN_newbie
  • 5,492
  • 14
  • 59
  • 97

1 Answers1

2

A little late to the party but...

You specify Type: "HTTP" for ApiGatewayRootMethod but HTTP takes the API endpoint URL. The URI formation that you specify is taken by Type: "AWS".

From AWS docs:

The Uniform Resource Identifier (URI) for the integration.

If you specify HTTP for the Type property, specify the API endpoint URL.

If you specify MOCK for the Type property, don't specify this property.

If you specify AWS for the Type property, specify an AWS service that follows this form: arn:aws:apigateway:region:subdomain.service|service:path|action/service_api. For example, a Lambda function URI follows this form: arn:aws:apigateway:region:lambda:path/path. The path is usually in the form /2015-03-31/functions/LambdaFunctionARN/invocations. For more information, see the uri property of the Integration resource in the Amazon API Gateway REST API Reference.

If you specified HTTP or AWS for the Type property, you must specify this property.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-integration.html

Community
  • 1
  • 1
Nivi M
  • 101
  • 10