AWS Logo
Menu

How to set a Path in API Gateway with AWS SAM without Proxy

Customize Lambda integrations in API Gateway with AWS SAM and OpenAPI. Implement non-proxy integrations for improved data handling in serverless apps.

Published Jan 27, 2025
Did you know that with API Gateway you can handle HTTP requests without worrying about servers? In serverless architectures, this service not only exposes your endpoints but also transforms and controls how data reaches your backend. In this tutorial, I'll teach you how to take it to the next level by configuring custom integrations with OpenAPI.

What is Lambda Proxy Integration and when to avoid it?

When we use AWS SAM to define our serverless architecture, the default integration between Lambda and API Gateway is Lambda Proxy Integration. This means that the entire HTTP request (headers, body, query parameters) is passed directly as a JSON event to the Lambda function. Although this approach is convenient, it's not always ideal. If you need to transform requests or connect to other services directly from API Gateway, a custom integration is the best option.

Defining the Lambda function

Let's start by creating our Lambda function in the AWS SAM template. We'll configure its main properties. Since we want to use a custom integration, we'll omit the Events property.

Defining the API Gateway

Next, we'll manually configure our API Gateway to avoid the default Lambda Proxy Integration behavior. We'll use the DefinitionBody property to define the API in OpenAPI format:

Configuring a custom integration

Now we'll specify the custom integration for our path. We'll use the x-amazon-apigateway-integration extension:

Conclusion

With this configuration, we have set up a custom integration that gives us complete control over how requests and responses are handled. This opens the door to more advanced and flexible architectures in AWS.
If you want to learn more about properties like passthroughBehavior or x-amazon-apigateway-integration, check the official AWS documentation.
 

Comments