View a markdown version of this page

Server-side logic - AWS Amplify

Server-side logic

Server-side logic is code that runs on a server, where your users can’t read or change it. Use it to handle payment webhooks, call third-party APIs with your own keys, call AI models, and run background and scheduled jobs.

Where your code runs

You have two options for server-side logic. Choose which option to use based on your use case:

  • Server code in your app – Route handlers and other server code in your framework, such as a Next.js route handler. It deploys with your app. Use it for requests from your website.

  • AWS Lambda functions – Functions that you deploy to your AWS account with their own tools, such as the AWS Serverless Application Model (AWS SAM). Use them for jobs that run on a schedule, react to events from other AWS services, or run for longer than a request from your website.

How your code calls the backend

Both kinds of code call the Amplify backend with the backend client SDK, in one of two ways:

  • As the signed-in user – Your code sends the user’s token with each request. The data API returns and changes only the rows allowed by the row-level security (RLS) policies that you configured. For more information, see Secure your data.

  • With full access – Your code signs each request with AWS credentials and runs as service_role, with access to every row. For more information, see API keys and roles.

To add and deploy server-side logic, see the following pages:

To store your users' files in Amazon S3, with access decided by your RLS policies, see How to perform user access control with the backend.