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:
-
Add server code to your app – Call the backend from a route handler, with full access or as the signed-in user.
-
Connect an AWS Lambda function – Give a function access to a backend branch, and call it from your app.
-
Deploy functions with your app – Deploy one function for each environment, in step with your app.
-
Run a function on a schedule – Run a job at a set rate with Amazon EventBridge Scheduler.
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.