0

Questions:

  • IntegrationResponse to Sam template ? Is it possible without OpenApi?
  • Way to add headers to GatewayResponses in SAM template?

What im trying to achive:

  • Define gateway responses and integration responses inside a SAM CloudFront template.

What i checked so far:

I was checking SAM github but for me it wasnt clear how to do it based on the above link. Also i didnt found any answer on stackoverflow which would explain why the headers are bad in my gatewayresponse snippet

Every Help is appreciated

Some examples:

Globals:
  Api:
    GatewayResponses:
      MISSING_AUTHENTICATION_TOKEN:
        ResponseParameters:
        #  gatewayresponse.header.Cache-Control: "no-cache"
        ResponseTemplates: 
          "application/json" : '{"errors": [{errorKey: "error Value"}]}'
        StatusCode: '404'
        #defaultResponse: true

Expected function level integrationResponse:

  Function:
    Type: AWS::Serverless::Function
    Properties:
      Handler: Function.handler
      Timeout: 20
      CodeUri: "src/Function"
      Role: .......
      Events:
        FunctionGet:
          Type: Api
          Properties:
            Path: /Function
            Method: get
            IntegrationResponse:
              SOME_ERROR_CODE
                ResponseTemplates
                  integrationresponse.header

1 Answers1

1

So long story short half of my question is stupid. in proxy integration API GW is by defult returning the response from server to client no need further declaration in SAM template.

As for the headers the following way is the correct:

Globals:
  Api:
    GatewayResponses:
      MISSING_AUTHENTICATION_TOKEN:
        ResponseParameters:
          Headers:
            Access-Control-Allow-Origin: "'*'"
            Access-Control-Allow-Headers: "'*'"
            Cache-Control: "'no-cache'"
            Content-Type: "'application/json'"
        ResponseTemplates: 
           "application/json" : '{"errors": [{errorKey: "error Value"}]}'
        StatusCode: '404'
        #defaultResponse: true