# Configurar credenciais
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_DEFAULT_REGION="us-east-1"
# Verificar credenciais
aws sts get-caller-identity
# Ver região configurada
aws configure get regioncd cdk
# Bootstrap (apenas primeira vez)
npx cdk bootstrap
# Ver mudanças antes de aplicar
npx cdk diff
# Ver template CloudFormation
npx cdk synth
# Deploy
npx cdk deploy --all
# Deploy sem confirmação
npx cdk deploy --all --require-approval never
# Destruir todos os recursos
npx cdk destroy --all --forcecd webapp
# Instalar dependências
npm ci
# Executar migrations do Prisma
npx prisma db push
# Rodar servidor de desenvolvimento
npm run dev
# Build de produção
npm run build| Arquivo | Descrição |
|---|---|
cdk/bin/cdk.ts |
Ponto de entrada do CDK |
cdk/lib/main-stack.ts |
Stack principal - MODIFICAR AQUI |
cdk/lib/constructs/ |
Componentes AWS reutilizáveis |
webapp/src/app/(root)/page.tsx |
Página principal da aplicação |
webapp/src/app/(root)/actions.ts |
Server Actions (backend) |
webapp/prisma/schema.prisma |
Schema do banco de dados |
// cdk/lib/main-stack.ts
// 1. VPC (Rede)
const vpc = new Vpc(this, 'Vpc', {...});
// 2. Database (Aurora PostgreSQL)
const database = new Database(this, 'Database', { vpc });
// 3. Auth (Cognito)
const auth = new Auth(this, 'Auth', {...});
// 4. EventBus (AppSync Events)
const eventBus = new EventBus(this, 'EventBus', {});
eventBus.addUserPoolProvider(auth.userPool);
// 5. AsyncJob (Lambda para jobs)
const asyncJob = new AsyncJob(this, 'AsyncJob', { database, eventBus });
// 6. Webapp (Next.js Lambda)
const webapp = new Webapp(this, 'Webapp', {
database, auth, eventBus, asyncJob, ...
});Após cdk deploy, você receberá:
# URL da aplicação
ServerlessWebappStarterKitStack.FrontendDomainName = https://xxx.cloudfront.net
# Cognito IDs
ServerlessWebappStarterKitStack.AuthUserPoolId = us-east-1_xxx
ServerlessWebappStarterKitStack.AuthUserPoolClientId = xxx
# Comandos úteis
ServerlessWebappStarterKitStack.DatabasePortForwardCommand = aws ssm start-session...
ServerlessWebappStarterKitStack.DatabaseSecretsCommand = aws secretsmanager get-secret-value...// Manter apenas:
const vpc = new Vpc(...);
const database = new Database(...);
// Comentar todo o resto// Adicionar:
const auth = new Auth(...);
const eventBus = new EventBus(...);
eventBus.addUserPoolProvider(auth.userPool);
// Manter asyncJob e webapp comentados// Descomentar tudo:
const asyncJob = new AsyncJob(...);
const webapp = new Webapp(...);# Ver logs detalhados no deploy
npx cdk deploy --all --verbose
# Ver o que será criado
npx cdk synth
# Verificar credenciais
aws sts get-caller-identity
# Verificar status Docker
docker ps| Serviço | Uso |
|---|---|
| VPC | Rede virtual isolada |
| NAT Instance | Internet para recursos privados |
| Aurora Serverless v2 | PostgreSQL serverless |
| Lambda | Aplicação Next.js |
| CloudFront | CDN global |
| Cognito | Autenticação |
| AppSync Events | WebSockets real-time |
| CloudWatch | Logs e métricas |
Ctrl + ```: Abrir/fechar terminalCtrl + P: Buscar arquivoCtrl + Shift + P: Command paletteCtrl + /: Comentar/descomentar linhaAlt + Up/Down: Mover linhaCtrl + D: Selecionar próxima ocorrência
- Consulte os logs no CloudWatch
- Pergunte ao instrutor
- Use
cdk synthpara ver o template gerado - Verifique credenciais com
aws sts get-caller-identity
💡 Dica: Mantenha este arquivo aberto em uma aba separada durante o workshop!