DEV Community

Alex Spinov
Alex Spinov

Posted on

AWS Amplify Has a Free API You Should Know About

AWS Amplify Gen 2 lets you define your entire backend in TypeScript — auth, data, storage, functions — all deployed to AWS.

Define Your Data Model

// amplify/data/resource.ts
import { a, defineData, type ClientSchema } from '@aws-amplify/backend'

const schema = a.schema({
  Todo: a.model({
    title: a.string().required(),
    completed: a.boolean().default(false),
    priority: a.enum(['low', 'medium', 'high']),
    owner: a.string()
  })
  .authorization(allow => [
    allow.owner(),
    allow.authenticated().to(['read'])
  ])
})

export type Schema = ClientSchema<typeof schema>
export const data = defineData({ schema })
Enter fullscreen mode Exit fullscreen mode

Query from Frontend

import { generateClient } from 'aws-amplify/data'
import type { Schema } from '../amplify/data/resource'

const client = generateClient<Schema>()

// List todos (typed!)
const { data: todos } = await client.models.Todo.list({
  filter: { completed: { eq: false } }
})

// Create
const { data: newTodo } = await client.models.Todo.create({
  title: 'Learn Amplify',
  priority: 'high'
})

// Real-time subscription
client.models.Todo.observeQuery().subscribe({
  next: ({ items }) => setTodos(items)
})
Enter fullscreen mode Exit fullscreen mode

Auth

// amplify/auth/resource.ts
import { defineAuth } from '@aws-amplify/backend'

export const auth = defineAuth({
  loginWith: {
    email: true,
    externalProviders: {
      google: {
        clientId: secret('GOOGLE_CLIENT_ID'),
        clientSecret: secret('GOOGLE_CLIENT_SECRET')
      },
      callbackUrls: ['http://localhost:3000/'],
      logoutUrls: ['http://localhost:3000/']
    }
  }
})
Enter fullscreen mode Exit fullscreen mode

Storage

// amplify/storage/resource.ts
import { defineStorage } from '@aws-amplify/backend'

export const storage = defineStorage({
  name: 'myFiles',
  access: (allow) => ({
    'profile-pictures/{entity_id}/*': [
      allow.entity('identity').to(['read', 'write', 'delete'])
    ],
    'public/*': [
      allow.authenticated.to(['read']),
      allow.guest.to(['read'])
    ]
  })
})

// Upload from frontend
import { uploadData } from 'aws-amplify/storage'
await uploadData({
  path: `profile-pictures/${userId}/avatar.jpg`,
  data: file
})
Enter fullscreen mode Exit fullscreen mode

Custom Functions

// amplify/functions/process-order/resource.ts
import { defineFunction } from '@aws-amplify/backend'

export const processOrder = defineFunction({
  name: 'process-order',
  entry: './handler.ts',
  timeoutSeconds: 30
})

// handler.ts
export const handler = async (event) => {
  const order = JSON.parse(event.body)
  await processPayment(order)
  await sendConfirmation(order.email)
  return { statusCode: 200, body: JSON.stringify({ success: true }) }
}
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

A mobile team needed auth + API + file storage + real-time sync for their app. Building from scratch on AWS: Cognito + AppSync + DynamoDB + S3 + IAM = weeks of configuration. With Amplify Gen 2: TypeScript schema, npx ampx sandbox for instant dev environment. They had a working backend in one afternoon.

Amplify Gen 2 is AWS made approachable for application developers.


Build Smarter Data Pipelines

Need to scrape websites, extract APIs, or automate data collection? Check out my ready-to-use scrapers on Apify — no coding required.

Custom scraping solution? Email me at spinov001@gmail.com — fast turnaround, fair prices.

Top comments (0)