Search code examples
amazon-web-servicesaws-api-gatewaydevopsserverlessserverless-application-model

Deploy REST API with HTTP Endpoint Integration using SAM AWS?


I'm new to AWS SAM deployment. I have a use case to automate the deployment using SAM AWS. Having a Rest API GW with another HTTP endpoint invocation. I searched pretty more docs but I didn't find any solution for this. Could you mind suggest me how to do this case?

Thanks in advance. Karthikeyan B


Solution

  • Sample template you can try for creating integration -

    AWSTemplateFormatVersion: '2010-09-09'
    Transform: AWS::Serverless-2016-10-31
    Description: AWS SAM template with a HTTP integration
    Resources:
      ApiGatewayApi:
        Type: AWS::Serverless::Api
        Properties:
          StageName: prod
          DefinitionBody: {
            "swagger": "2.0",
            "info": {
              "version": "1.0"
            },
            "paths": {
              "test": {
                "get": {
                  "produces": [
                    "application/json"
                  ],
                  "responses": {
                    "200": {
                      "description": "200 response"
                    }
                  },
                  "x-amazon-apigateway-integration": {
                    "responses": {
                      "default": {
                        "statusCode": "200"
                      }
                    },
                    "credentials": "arn:aws:iam::account-id:role/role-name",
                    "uri": "https://www.example.com",
                    "passthroughBehavior": "when_no_match",
                    "httpMethod": "GET",
                    "type": "http_proxy"
                  }
                }
              }
            }
        }
    

    Deploy the template using CLI -

    $ sam deploy --stack-name httpProxy -t httpProxy.yaml --capabilities CAPABILITY_IAM