# API gateway integration with SQS

**URL:** <https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339>\
**Category:** Serverless Framework\
**Created:** [February 11, 2019, 11:42am UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339 "2019-02-11T11:42:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![teddmason](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/teddmason/32/3032_2.png) [@teddmason](https://forum.serverless.com/u/teddmason)\
**Post date:** [February 11, 2019, 11:42am UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339/1 "2019-02-11T11:42:53Z")

</div>

I have a small Serverless application which is an API gateway with lambda events, all good.

I now have some requirements that means that I need an SQS resource in front of one of the lambda functions as there is a need for replays.

I would like to be able to get my serverless app to create an api gateway endpoint that forwards on the request to SQS (the queue would then be added as an event for the lambda function. All possible through the AWS console, but I don’t know if this can be done through serverless.

I know through serverless I could have an intermediate lambda function, that has an apigateway event, that then forwards the request to SQS, which in turn calls the proper lambda function, but this is an extra step that I don’t think should be needed.

Can anyone advise on the best way to achieve this?

---

<div class="post-metadata">

**Author:** ![matt2xu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/matt2xu/32/3196_2.png) [@matt2xu](https://forum.serverless.com/u/matt2xu)\
**Post date:** [June 6, 2019, 12:56pm UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339/2 "2019-06-06T12:56:09Z")

</div>

We are in the process of migrating raw CloudFormation templates to Serverless framework, and we will be having the same need soon enough. I didn’t see another integration for API Gateway than “lambda”. Is there hope that a “awsService” integration would be supported soon enough? Or should we handle that with a plugin?

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![Mihailoff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mihailoff/32/3339_2.png) [@Mihailoff](https://forum.serverless.com/u/Mihailoff)\
**Post date:** [July 14, 2019, 3:18pm UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339/3 "2019-07-14T15:18:01Z")

</div>

Had anyone sorted this out?

---

<div class="post-metadata">

**Author:** ![oscarmrom](https://avatars.discourse-cdn.com/v4/letter/o/3da27b/32.png) [@oscarmrom](https://forum.serverless.com/u/oscarmrom)\
**Post date:** [May 7, 2020, 1:38pm UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339/4 "2020-05-07T13:38:10Z")

</div>

Did anyone manage to find a solution for this?

I am also trying to put an SQS queue behind an API Gateway endpoint.

---

<div class="post-metadata">

**Author:** ![joaobispo2077](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/joaobispo2077/32/5431_2.png) [@joaobispo2077](https://forum.serverless.com/u/joaobispo2077)\
**Post date:** [March 24, 2021, 1:47pm UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339/5 "2021-03-24T13:47:31Z")

</div>

I have the same issue, I need make integration api gateway-sqs.

I found plugins like:

- [serverless-apigateway-service-proxy](https://www.serverless.com/plugins/serverless-apigateway-service-proxy#sqs)
- [serverless-apigw](https://www.serverless.com/plugins/serverless-apigw-sqs-plugin)

However, they are incompatible with versions major than \>1.8 of Serverless Framework and im using version major 2.

I know that this is possible by cloudformation in the Serverless Framework, but the configuration is not intuitive for me.

If anyone found a simple way or just a way for this integration api gateway-sqs by Serverless Framework, please help us.

---

<div class="post-metadata">

**Author:** ![sanjay01112000](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@sanjay01112000](https://forum.serverless.com/u/sanjay01112000)\
**Post date:** [February 23, 2024, 6:05am UTC](https://forum.serverless.com/t/api-gateway-integration-with-sqs/7339/6 "2024-02-23T06:05:50Z")

</div>

Hi, I found a solution.

```auto
resources:
  Resources:
    # Define an AWS API Gateway named MyApi
    MyApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: MyApi

    # Define a resource named serverless under MyApi
    ProxyResource:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId: !GetAtt MyApi.RootResourceId
        PathPart: serverless
        RestApiId: !Ref MyApi

    # Define a POST method for the serverless resource
    ProxyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        AuthorizationType: NONE
        ResourceId: !Ref ProxyResource
        RestApiId: !Ref MyApi
        HttpMethod: POST

        # Integration details for the method
        Integration:
          Credentials: arn:aws:iam::${param:account, 'your_account_id'}:role/system.role
          IntegrationHttpMethod: POST
          Type: AWS
          Uri: !Sub 'arn:aws:apigateway:${param:region, 'your_region'}:sqs:path/your_account_id/your_queue'
          IntegrationResponses:
            - StatusCode: 200
          RequestTemplates:
            application/json: |
              Action=SendMessage&MessageBody=$input.body
          RequestParameters:
            integration.request.querystring.MessageBody: "method.request.body"
            integration.request.header.Content-Type: "'application/x-www-form-urlencoded'"

        # Method response details
        MethodResponses:
          - ResponseModels: { "application/json": "Empty" }
            StatusCode: 200
        RequestParameters:
          method.request.header.AnotherHeader: false

    # Define an API Gateway stage named serverless
    ApiGatewayStage:
      Type: AWS::ApiGateway::Stage
      Properties:
        StageName: serverless
        RestApiId: !Ref MyApi
        DeploymentId: !GetAtt ApiGatewayDeployment.DeploymentId

    # Define an API Gateway deployment
    ApiGatewayDeployment:
      Type: AWS::ApiGateway::Deployment
      DependsOn: ProxyMethod
      Properties:
        RestApiId: !Ref MyApi

```

`${param:account, 'your_account_id'}` : Replace ‘your\_account\_id’ with your AWS account ID.  
`${param:region, 'your_region'}` : Replace ‘your\_region’ with the AWS region you want to use.  
Replace ‘ **your\_queue** ’ with the name of your SQS queue.
