0

i use the serverless framework and would like to deploy an API Gateway HTTP Proxy but i don't have a Lambda function connected with API Gateway.

I found this in the internet, but this example require one lambda function connected to API Gateway

#    ProxyResource:
#      Type: AWS::ApiGateway::Resource
#      Properties:
#        ParentId:
#          Fn::GetAtt:
#            - ApiGatewayRestApi # our default Rest API logical ID
#            - RootResourceId
#        PathPart: serverless # the endpoint in your API that is set as proxy
#        RestApiId:
#          Ref: ApiGatewayRestApi
#    ProxyMethod:
#      Type: AWS::ApiGateway::Method
#      Properties:
#        ResourceId:
#          Ref: ProxyResource
#        RestApiId:
#          Ref: ApiGatewayRestApi
#        HttpMethod: GET # the method of your proxy. Is it GET or POST or ... ?
#        MethodResponses:
#          - StatusCode: 200
#        Integration:
#          IntegrationHttpMethod: POST
#          Type: HTTP
#          Uri: http://serverless.com # the URL you want to set a proxy to
#          IntegrationResponses:
#            - StatusCode: 200

If i deploy this i got the error:

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

It is possible to deploy just an API Gateway HTTP Proxy ?

Thanks

2
  • Could I ask what you're trying to achieve? Commented Jul 22, 2018 at 10:31
  • I've a running AppSync Service but this service needs an Authentication (the minimum is an API key). I'm not happy to pass always the ApiKey to my Application and would like to create an API Gateway Proxy which pass the API Key to AppSync. So that i don't need to change the ApiKey every year (p.e. in mobile apps). Commented Jul 22, 2018 at 10:41

1 Answer 1

1

I figure out how to create an API Gateway if i don't have any lambda function in serverless. I just need to add this to resources and change Ref: ApiGatewayRestApi to Ref: ProxyApi

resources:
  Resources:
    ProxyApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: ApiGateway

To fulfill my requirement to use AppSync without any ApiKey - it's possible with these lines:

    ProxyApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: AppSync Graph Proxy

    ProxyResource:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Fn::GetAtt:
            - ProxyApi # our default Rest API logical ID
            - RootResourceId
        PathPart: graphql # the endpoint in your API that is set as proxy
        RestApiId:
          Ref: ProxyApi
    ProxyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        ResourceId:
          Ref: ProxyResource
        RestApiId:
          Ref: ProxyApi
        AuthorizationType: NONE
        HttpMethod: ANY # the method of your proxy. Is it GET or POST or ... ?
        MethodResponses:
          - StatusCode: 200
        Integration:
          IntegrationHttpMethod: POST
          Type: HTTP
          Uri: { Fn::GetAtt: [GraphQlApi, GraphQLUrl] } # the URL you want to set a proxy to
          IntegrationResponses:
            - StatusCode: 200
          RequestParameters:
            "integration.request.header.x-api-key": "stageVariables.API_KEY"
    ProxyDeployment:
      Type: AWS::ApiGateway::Deployment
      DependsOn: "ProxyMethod"
      Properties:
        RestApiId:
          Ref: ProxyApi

    ProxyStage:
      Type: AWS::ApiGateway::Stage
      Properties:
        StageName: ${opt:stage, self:provider.stage}
        RestApiId:
          Ref: ProxyApi
        DeploymentId:
          Ref: ProxyDeployment
        Variables:
          API_KEY: { Fn::GetAtt: [GraphQlApiKeyDefault, ApiKey] }

For this, you need an working and configured serverless-appsync-plugin in your serverless config

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.