Skip to content

Loads of API features, bug fixes and improvements

Compare
Choose a tag to compare
@sanathkr sanathkr released this 12 Mar 23:02
· 565 commits to master since this release

This one is a big release! So grab a popcorn 🍿 and start reading:

API Features

CORS, yeah CORS!

You can now add CORS to your SAM apps in one line Cors: "'www.example.com'"! This will allow a webpage at "www.example.com" to call your APIs. As a bonus, SAM will automatically create the correct AllowMethods headers to allow only the methods served on each API Path. If you want, you can override other Cors properties by passing a dictionary. Checkout the Spec for full configuration.

CORS is probably the most talked about issue in this Github repo (39 issues mention CORS). We are thrilled to get this out :)

Learn more in this example

Regional Endpoints

If you want to connect the API to your own CloudFront distribution, or want to use it with Lambda@Edge, or just want to API reduce latency, you can now make your APIs Regional by setting EndpointConfiguration: REGIONAL in your API.

Binary Media Types

Send images, pdf, or any binary data through your APIs by adding the following configuration:

BinaryMediaTypes:
  # API Gateway will convert ~1 to / 
  - image~1png
  - image~1gif

Don't forget to set isBase64Encoded: true in your Lambda function response. Checkout this full example for more details

Logging, Metrics, CacheTTL: Any Stage Settings

To add logging or turn on metrics or set the CacheTTL, you can now do that in the MethodSettings property of your SAM template. The value of this property is directly passed through to CloudFormation. So any feature available in CloudFormation MethodSettings property will be available to you in SAM:

    MethodSettings: [{
        # Turn on Info logging
        "LoggingLevel": "INFO",

        # Enable Metrics
        "MetricsEnabled": True,

        # Trace-level Logging
        "DataTraceEnabled": True,

        # On all Paths & methods
        "ResourcePath": "/*",
        "HttpMethod": "*",
    }]

Refer to resources generated by SAM

SAM will generate an API Gateway Stage and API Gateway Deployment for every AWS::Serverless::Api resource. If you want to refer to these properties in an intrinsic function such as Ref or Fn::GetAtt, you can append .Stage and .Deployment suffix to the API's Logical ID. SAM will convert it to the correct Logical ID of the auto-generated Stage or Deployment resource respectively.

  • !Ref MyApi.Stage => Ref the Stage generated by SAM
  • !Ref MyApi.Deployment => Ref the Deployment resource generated by SAM

This allows you to connect SAM generated resources with other CloudFormation resources. This is super important, especially, if you want to refer to the Deployment resource whose Logical ID keeps changing during every deployment.

Function

Per Function Concurrency

This property allows you to set a concurrency limit to each of your Lambda functions. Use this by adding ReservedConcurrentExecutions property to your Function resource

SimpleTable

TableName, and Tags properties are now available

Bug Fixes

  • Managed policy ARNs, and intrinsic functions for managed policies are now supported.
  • We will throw an error if invalid value for function policies are specified, instead of passing the value to CloudFormation
  • Support Integers in Tags of Serverless::Function
  • BucketEncryption property of S3 resource should work now(#275)

New Regions

SAM is now available in all regions that Lambda is available including AWS GovCloud (US) and AWS China (Beijing) Region. Refer to the Region table for all the regions that Lambda is available in.

Documentation Updates 📖

  • SAM Internals: Take a look under-the-hood of how SAM generates CloudFormation resources and learn about the naming convention used by SAM
  • CloudFormation compatibility - SAM is built on top of CloudFormation, which means you want to be able to use all the cool features CloudFormation offers such as Intrinsic Functions, DependsOn, Conditions etc. SAM's support for CloudFormation features is not 100%. So read this document to understand what works and what does not. If a missing feature is blocking you, then create a Github Issue and let us know!
  • FAQs - We have started collecting common questions and answers into a separate document. Thanks to @sgarcez for starting this!

CONTRIBUTORS NEEDED

We are laying the ground work to create a Sphinx based documentation website for SAM. Documentation from the docs folder will be rendered there in a pretty UI. Check it out - https://awslabs.github.io/serverless-application-model/

As you noticed, this website looks bare and empty. We are still in the process of improving the UI, adding more documentation and surfacing relevant information. Our hope is to make this the Go-To destination for all things SAM.

If you are using SAM, and love it, and want to earn some Karma, help us build this website. It is a simple static website created with Sphinx. You can find the source code the website at ./docs/website. There is a Makefile to get you up and running. We are looking for all sorts of help:

  • Add more docs (#251)
  • Improve README.md to help people get started with SAM easier. Checkout README.md in my fork to get a sense of general direction.
  • Improve website UI - Write a new Sphinx theme and write a neat UI

Start Hacking!

👩‍💻👨‍💻 => 🐿