Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Choose your framework/language

Page updated May 28, 2024

Set up Amplify HTTP API

Using the AWS Cloud Development Kit (AWS CDK), you can configure Amplify Functions as resolvers for routes of an HTTP API powered by Amazon API Gateway.

Set up HTTP API with Lambda Function

To get started, create a new directory and a resource file, amplify/functions/api-function/resource.ts. Then, define the function with defineFunction:

import { defineFunction } from "@aws-amplify/backend";
export const myApiFunction = defineFunction({
name: "api-function",

Then, create the corresponding handler file, amplify/functions/api-function/handler.ts, file with the following contents:

import type { APIGatewayProxyHandlerV2 } from "aws-lambda";
export const handler: APIGatewayProxyHandlerV2 = async (event) => {
console.log("event", event);
return {
statusCode: 200,
// Modify the CORS settings below to match your specific requirements
headers: {
"Access-Control-Allow-Origin": "*", // Restrict this to domains you trust
"Access-Control-Allow-Headers": "*", // Specify only the headers you need to allow
body: JSON.stringify("Hello from api-function!"),

Next, using the AWS CDK, create an HTTP API in your backend file:

import { defineBackend } from "@aws-amplify/backend";
import { Stack } from "aws-cdk-lib";
import {
} from "aws-cdk-lib/aws-apigatewayv2";
import {
} from "aws-cdk-lib/aws-apigatewayv2-authorizers";
import { HttpLambdaIntegration } from "aws-cdk-lib/aws-apigatewayv2-integrations";
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
import { myApiFunction } from "./functions/api-function/resource";
import { auth } from "./auth/resource";
import { data } from "./data/resource";
const backend = defineBackend({
// create a new API stack
const apiStack = backend.createStack("api-stack");
// create a IAM authorizer
const iamAuthorizer = new HttpIamAuthorizer();
// create a User Pool authorizer
const userPoolAuthorizer = new HttpUserPoolAuthorizer(
userPoolClients: [backend.auth.resources.userPoolClient],
// create a new HTTP Lambda integration
const httpLambdaIntegration = new HttpLambdaIntegration(
// create a new HTTP API with IAM as default authorizer
const httpApi = new HttpApi(apiStack, "HttpApi", {
apiName: "myHttpApi",
defaultAuthorizer: iamAuthorizer,
corsPreflight: {
// Modify the CORS settings below to match your specific requirements
allowMethods: [
// Restrict this to domains you trust
allowOrigins: ["*"],
// Specify only the headers you need to allow
allowHeaders: ["*"],
createDefaultStage: true,
// add routes to the API with a IAM authorizer and different methods
path: "/items",
methods: [HttpMethod.GET, HttpMethod.PUT, HttpMethod.POST, HttpMethod.DELETE],
integration: httpLambdaIntegration,
authorizer: iamAuthorizer,
// add a proxy resource path to the API
path: "/items/{proxy+}",
methods: [HttpMethod.OPTIONS, HttpMethod.ANY],
integration: httpLambdaIntegration,
// add route to the API with a User Pool authorizer
path: "/cognito-auth-path",
methods: [HttpMethod.GET],
integration: httpLambdaIntegration,
authorizer: userPoolAuthorizer,
// create a new IAM policy to allow Invoke access to the API
const apiPolicy = new Policy(apiStack, "ApiPolicy", {
statements: [
new PolicyStatement({
actions: ["execute-api:Invoke"],
resources: [
// attach the policy to the authenticated and unauthenticated IAM roles
// add outputs to the configuration file
custom: {
API: {
[httpApi.httpApiName!]: {
endpoint: httpApi.url,
region: Stack.of(httpApi).region,
apiName: httpApi.httpApiName,

Install Amplify Libraries

Use the package manager of your choice to install the Amplify JavaScript library. For example, with npm:

npm add aws-amplify

Use the package manager of your choice to install the Amplify JavaScript library. For example, with npm:

Instructions for React Native version 0.72 and below

@aws-amplify/react-native requires a minimum iOS deployment target of 13.0 if you are using react-native version less than or equal to 0.72. Open the Podfile located in the ios directory and update the target value:

- platform :ios, min_ios_version_supported
+ platform :ios, 13.0
npm add aws-amplify @aws-amplify/react-native

Initialize Amplify API

To initialize the Amplify API category you need to configure Amplify with Amplify.configure().

Import and load the configuration file in your app. It's recommended you add the Amplify configuration step to your app's root entry point. For example src/main.ts:

import { Amplify } from 'aws-amplify';
import outputs from '../amplify_outputs.json';
const existingConfig = Amplify.getConfig();
API: {
REST: outputs.custom.API,

Make sure you call Amplify.configure as early as possible in your application’s life-cycle. A missing configuration or NoCredentials error is thrown if Amplify.configure has not been called before other Amplify JavaScript APIs. Review the Library Not Configured Troubleshooting guide for possible causes of this issue.