How to create 'integration' request details on a Serverless function event in YAML?

I am trying to setup a serverless implementation that can deploy a non-lambda http passthrough integration. See the following relevant YAML snippet:

functions:
  hello:
    handler: src/dummyHandler.dummy
    events:
      - http:
          path: account/{id}
          method: get
          integration: http
          request:
            uri: "https://myurl/api/account/{id}"
            parameters:
              method.request.path.id: true

My question is how do I define the information that shows up on AWS API Gateway in the ‘Integration request’ view? I expected being able to add integration.request.path.id: true to the definition would make sense but that doesn’t work. See below for an example of the screen I am trying to emulate - this was created manually - notice the path variable that I would like to define in the YAML document.

image

I was expecting some definition around the ‘integration’ tag but nothing I have tried works. Can this even be generated using Serverless?

1 Like

You’re close.
I had the same issue when trying to set up a pass-through to CloudSearch. tracked it down to using the following format:

  search:
    handler: src/dummy.handler
    events:
      - http:
          path: /restapi/v1/search
          method: get
          cors: true
          authorizer:
            arn: ${self:custom.user-pool-arn}
          integration: http
          request:
            method: get
            uri: ${self:custom.search-url}
            parameters:
              'method.request.querystring.fq': false
              'method.request.querystring.pretty': false
              'method.request.querystring.q': true
              'method.request.querystring.q.cursor': false
              'method.request.querystring.q.options': false
              'method.request.querystring.q.parser': false
              'method.request.querystring.return': false
              'method.request.querystring.size': false
              'method.request.querystring.sort': false
              'method.request.querystring.start': false
            template:
              $input.path('$')
          response:
            statusCodes:
              200:
                pattern: ''

I did(and still do) have one other problem in that while the api gateway handles receipt of the query string params now, it doesn’t automatically add them to the CloudFormation file.
To get around that I do:
sls package -p foo -s <stage>
Update the ‘foo/serverless-state.json’ file to add the following:

doc.service.provider.compiledCloudFormationTemplate.Resources.ApiGatewayMethodRestapiV1SearchGet.Properties.Integration.RequestParameters = 
{
  'integration.request.querystring.fq': 'method.request.querystring.fq',
  'integration.request.querystring.pretty': 'method.request.querystring.pretty',
  'integration.request.querystring.q': 'method.request.querystring.q',
  'integration.request.querystring.q.cursor': 'method.request.querystring.q.cursor',
  'integration.request.querystring.q.options': 'method.request.querystring.q.options',
  'integration.request.querystring.q.parser': 'method.request.querystring.q.parser',
  'integration.request.querystring.return': 'method.request.querystring.return',
  'integration.request.querystring.size': 'method.request.querystring.size',
  'integration.request.querystring.sort': 'method.request.querystring.sort',
  'integration.request.querystring.start': 'method.request.querystring.start'
}

Then sls deploy -p foo -s <stage>

Bit of a nuisance, but at the time, I wasn’t able to find another way around it.

Hope it helps.

1 Like

Hi,

I am struck in similar situation, but on POST. I want to assign a model to request body. But I don’t know how to define the same in yml file.

api-resource-body

I am trying the following,

functions:
  auditLog:
    handler: handler.auditLog
    description: Stores the log details
    Type: "AWS::ApiGateway::RestApi"
    events:
      - http:
          path: auditLog
          method: post
          cors: true
          authorizer: apiAuth
          request:
            parameters:
              body: {"title":"auditLog","type":"object","properties":{"serviceName":{"type":"string"},"userID":{"type":"string","format":"email"}}}
              application/json: '{ body: {"title":"auditLog","type":"object","properties":{"serviceName":{"type":"string"},"userID":{"type":"string","format":"email"}}}}'

Can you please let me know, how the yml should be defined.

Thanks

Satheesh

Hi,

On to my future investigation and googling through I found Serverless AWS Documentation plugin which helps in deploying model definition from yml as well as documentation.

You can find the more on there,

Thanks,

Satheesh

To achieve programmatic setting of the integration request header I had to package the code using serverless, then use a python script to manually set the hard coded value within the cloudformation then use serverless to deploy the updated package.

Thread here