JAck28
JAck28

Reputation: 907

Set TTL for API Gateway in Swagger

I'm using cloudformation, and have enabled caching like this:

  Type: AWS::ApiGateway::Stage
  Properties:  
     CacheClusterEnabled: true
     CacheClusterSize: 0.5

My methods are taken from swagger. Here's my swagger file for GET

/v1/myPath/{id}:
get:
  tags:
    - Books
  operationId: getBook
  parameters:
    - name: id
      in: path
      description: The ID of the book to retrieve
      type: integer
      format: int32
      required: true
    - name: custom-header
      in: header
      type: string
  responses:
    '200':
  x-amazon-apigateway-integration:
    type: aws_proxy
    httpMethod: POST
    uri: arn:aws:apigateway:us-west-1:lambda:path...
    passthroughBehavior: when_no_match
    requestParameters:
      integration.request.header.custom-header: method.request.header.custom-header
    cacheKeyParameters:
      - method.request.header.custom-header

How can I set the caching TTL for my GET request in my swagger.yaml? I can't seem to find documentation for this.

Upvotes: 2

Views: 1904

Answers (1)

Kannaiyan
Kannaiyan

Reputation: 13055

Referring to documentation,

CacheTtlInSeconds: Integer

CacheTtlInSeconds
The time-to-live (TTL) period, in seconds, that specifies how long API Gateway caches responses.

Required: No

Type: Integer

Reference:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-deployment-stagedescription.html

Hope it helps.

EDIT1:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-methodresponse.html#cfn-apigateway-method-methodresponse-responseparameters

Cache-Control Documentation:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

Way to add headers to cloudformation,

ResponseParameters
Response parameters that API Gateway sends to the client that called a method. Specify response parameters as key-value pairs (string-to-Boolean maps), with a destination as the key and a Boolean as the value. Specify the destination using the following pattern: method.response.header.name, where the name is a valid, unique header name. The Boolean specifies whether a parameter is required.

Required: No

Type: Mapping of key-value pairs

Upvotes: 1

Related Questions