Serverless-application-model: Specifying payloadFormatVersion for implicit apis

Created on 13 Mar 2020  ·  4Comments  ·  Source: aws/serverless-application-model

Description:
Looking for the ability to specify the payloadFormatVersion for the route on an implicit HttpApi. I do not believe this is supported in Globals. The payloadFormatVersion defaults to the latest version if you do not specify it. There was a recent release of a 2.0 version and it broke our lambda integration which was expecting the 1.0 payload.

Steps to reproduce the issue:

{
  "Resources": {
    "MyFunction": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "Events": {
          "MyHttpApiEvent": {
            "Type": "HttpApi"
          }
        }
      }
    }
  }
}

Observed result:

{
  "ServerlessHttpApi": {
    "Type": "AWS::ApiGatewayV2::Api",
    "Properties": {
      "Body": {
        "info": {
          "version": "1.0",
          "title": {
            "Ref": "AWS::StackName"
          }
        },
        "paths": {
          "$default": {
            "x-amazon-apigateway-any-method": {
              "x-amazon-apigateway-integration": {
                "httpMethod": "POST",
                "type": "aws_proxy",
                "uri": {
                  "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations"
                },
                "payloadFormatVersion": "2.0"
              },
              "isDefaultRoute": true,
              "responses": {}
            }
          }
        }
      }
    }
  }
}

Expected result:
Need a way to produce "payloadFormatVersion": "1.0" without having to explicitly define all the resources.

Most helpful comment

@ShreyaGangishetty yeah, that was a rather large breaking change (as the change in the tests for that release show). I've commented on the PR for v1.22.0 – I hope such breaking changes can be avoided in the future (unless the transform version is bumped) 👍

All 4 comments

This works:

{
  "Events": {
    "MyHttpApiEvent": {
      "Type": "HttpApi",
      "Properties": {
        "PayloadFormatVersion": "1.0"
      }
  }
}

Thanks for this! I just broke too and found your post. Very helpful.

For those of us using SAM YAML...make sure you put the version in quotes. It's a string.

  Events:
    SomeEvent:
      Type: HttpApi
      Properties:
        PayloadFormatVersion: "1.0"
        ApiId: !Ref SomeHttpApiRef
        Path: /path/to/endpoint
        Method: [get, post etc.]

The default value of PayloadFormatVersion is "2.0" in SAM from v1.22.0 release. Refer to AWS SAM documentation for more information.

@ShreyaGangishetty yeah, that was a rather large breaking change (as the change in the tests for that release show). I've commented on the PR for v1.22.0 – I hope such breaking changes can be avoided in the future (unless the transform version is bumped) 👍

Was this page helpful?
0 / 5 - 0 ratings