Skip to content

Instantly share code, notes, and snippets.

@rujmah
Last active January 25, 2019 09:16
Show Gist options
  • Save rujmah/dfcd0ee8054d94d093ecea0c1bd334a1 to your computer and use it in GitHub Desktop.
Save rujmah/dfcd0ee8054d94d093ecea0c1bd334a1 to your computer and use it in GitHub Desktop.

Revisions

  1. rujmah revised this gist Jan 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,4 @@ This was apparently due to the fact that regardless of the actual `HttpMethod` w

    https://docs.amazonaws.cn/en_us/apigateway/latest/developerguide/set-up-lambda-custom-integrations.html

    > For Lambda integrations, you must use the HTTP method of POST for the integration request, according to the specification of the Lambda service action for function invocations. The uri parameter is the ARN of the function-invoking action.
    > For Lambda integrations, you must use the HTTP method of POST for the integration request, according to the specification of the Lambda service action for function invocations.
  2. rujmah revised this gist Jan 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # AWS API Gateway that calls an single endpoint
    # AWS API Gateway that calls an single endpoint Lambda with GET

    ## Pertinent info

  3. rujmah revised this gist Jan 25, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,8 @@ error message when attempting to use `GET` methods:
    </AccessDeniedException>
    ```

    This was apparently due to the fact that regardless of the actual `HttpMethod` we set, `IntegrationHttpMethod` needs to be set to `POST`
    This was apparently due to the fact that regardless of the actual `HttpMethod` we set, `IntegrationHttpMethod` needs to be set to `POST` as per this piece of AWS documentation:

    https://docs.amazonaws.cn/en_us/apigateway/latest/developerguide/set-up-lambda-custom-integrations.html

    > For Lambda integrations, you must use the HTTP method of POST for the integration request, according to the specification of the Lambda service action for function invocations. The uri parameter is the ARN of the function-invoking action.
  4. rujmah created this gist Jan 24, 2019.
    35 changes: 35 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # AWS API Gateway that calls an single endpoint

    ## Pertinent info

    Ensure `IntegrationHttpMethod` is set to `POST` even if you want to use a `GET` (or whatever)

    e.g.
    ```
    rootMethod:
    Type: AWS::ApiGateway::Method
    Properties:
    AuthorizationType: NONE
    HttpMethod: GET
    Integration:
    IntegrationHttpMethod: POST
    Type: AWS_PROXY
    Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations"
    ResourceId: !GetAtt apiGateway.RootResourceId
    RestApiId: !Ref apiGateway
    ```

    See this thread: https://forums.aws.amazon.com/thread.jspa?messageID=745275

    ## Background

    When attempting to set up an API Gateway with a single endpoint that used a Lambda we continually got the following
    error message when attempting to use `GET` methods:

    ```
    <AccessDeniedException>
    <Message>Unable to determine service/operation name to be authorized</Message>
    </AccessDeniedException>
    ```

    This was apparently due to the fact that regardless of the actual `HttpMethod` we set, `IntegrationHttpMethod` needs to be set to `POST`
    43 changes: 43 additions & 0 deletions apigateway_cfn.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    AWSTemplateFormatVersion: "2010-09-09"
    Description: Test API G setup

    Parameters:
    lambdaArn:
    Type: "String"
    Default: arn:aws:lambda:eu-west-1:xxxxxxxxxx:function:xxxxxxxxxx

    Resources:
    apiGateway:
    Type: AWS::ApiGateway::RestApi
    Properties:
    Name: rjjmTestApiGateway
    Description: "Test API Gateway"

    rootMethod:
    Type: AWS::ApiGateway::Method
    Properties:
    AuthorizationType: NONE
    HttpMethod: GET
    Integration:
    IntegrationHttpMethod: POST
    Type: AWS_PROXY
    Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations"
    ResourceId: !GetAtt apiGateway.RootResourceId
    RestApiId: !Ref apiGateway

    deployment:
    Type: AWS::ApiGateway::Deployment
    DependsOn: rootMethod
    Properties:
    RestApiId: !Ref apiGateway
    StageName: v1

    lambdaApiGatewayInvoke:
    Type: AWS::Lambda::Permission
    Properties:
    Action: lambda:InvokeFunction
    FunctionName: !Ref lambdaArn
    Principal: apigateway.amazonaws.com
    SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${apiGateway}/*"