AWS
O mesmo caminho do Google Cloud, com as peças da AWS: o site num bucket S3 servido pelo CloudFront, o corpus num segundo bucket que só o MCP lê, e o MCP no App Runner. O GitHub entra na AWS por OIDC, assumindo uma role, sem chave de acesso guardada.
É um ponto de partida: revise contra a sua conta antes do primeiro deploy.
O que criar
- Uma role IAM com confiança no provedor OIDC do GitHub (
token.actions.githubusercontent.com), restrita a este repositório, com permissão de escrever nos dois buckets, invalidar a distribuição do site, publicar no ECR e iniciar deploy no App Runner. - O bucket do site, privado, e uma distribuição CloudFront na frente dele com a função de rotas abaixo. A camada de acesso entra aqui: Cognito com Lambda@Edge, um ALB com OIDC ou o Verified Access, conforme o login da empresa.
- O bucket do corpus e uma segunda distribuição com a função de autorização abaixo. O MCP lê o corpus por
CONTENT_URL(a URL dessa distribuição) e mandaCONTENT_AUTHORIZATIONno cabeçalho. - Um repositório no ECR e um serviço no App Runner apontando para a tag
latest, com as variáveis do MCP (Operar o MCP) e os segredos no Secrets Manager. - As variáveis do repositório no GitHub:
AWS_ROLE_ARN,AWS_REGION,DOCS_BUCKET,DOCS_DISTRIBUTION_ID,CONTENT_BUCKET,MCP_ECR_REPOSITORYeMCP_APPRUNNER_SERVICE_ARN.
Para usar, copie os dois workflows para .github/workflows/ e descomente os jobs deploy-docs e deploy-mcp no fim do .github/workflows/release.yml.
O deploy das docs
# TEMPLATE (AWS): publishes the docs site to S3 behind CloudFront and the AI corpus to the bucket the MCP server reads.
# To use it, copy it to .github/workflows/deploy-docs.yml, uncomment its job at the end of release.yml
# and set the repo variables below.
# A starting point: review it against your account before the first run.
#
# Repo variables: AWS_ROLE_ARN (role GitHub assumes through OIDC), AWS_REGION, DOCS_BUCKET (the site),
# DOCS_DISTRIBUTION_ID (its CloudFront distribution), CONTENT_BUCKET (the corpus, served by the corpus distribution).
name: Deploy docs
on:
workflow_call:
inputs:
ref:
description: 'Version tag to deploy (v<x.y.z>)'
required: false
type: string
workflow_dispatch:
inputs:
ref:
description: 'Version tag to deploy (empty = the ref this run was started from)'
required: false
type: string
permissions:
contents: read
id-token: write
concurrency:
group: docs-deploy
cancel-in-progress: false
env:
LEFTHOOK: 0
jobs:
deploy:
if: vars.AWS_ROLE_ARN != ''
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
# Full history: the AI corpus dates each page by the last commit of its source file
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm turbo run build --filter @exemplo/docs
# GitHub OIDC: a short-lived session of the role, no access key stored
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
# The corpus does not go to the public site bucket: it has its own bucket and distribution
- name: Upload the site
run: |
aws s3 sync apps/docs/build "s3://${{ vars.DOCS_BUCKET }}" --delete --exclude ai-corpus.json
aws cloudfront create-invalidation --distribution-id "${{ vars.DOCS_DISTRIBUTION_ID }}" --paths "/*"
# The MCP server polls it by ETag (CONTENT_URL) and reloads within minutes
- name: Publish the AI corpus
run: |
aws s3 cp apps/docs/build/ai-corpus.json "s3://${{ vars.CONTENT_BUCKET }}/ai-corpus.json" \
--content-type application/json --cache-control no-cache
O deploy do MCP
A tag com a versão fica no ECR, e voltar uma versão é apontar o serviço para ela.
# TEMPLATE (AWS): builds the docs MCP server image, pushes it to ECR and deploys it on App Runner.
# To use it, copy it to .github/workflows/deploy-mcp.yml, uncomment its job at the end of release.yml
# and set the repo variables below.
# A starting point: review it against your account before the first run.
#
# Repo variables: AWS_ROLE_ARN, AWS_REGION, MCP_ECR_REPOSITORY (e.g. docs-mcp), MCP_APPRUNNER_SERVICE_ARN.
# The App Runner service points to the `latest` tag of that repository and keeps its own settings (env vars, secrets,
# scaling, ECR access role); this workflow only pushes a new image and starts a deployment.
name: Deploy MCP
on:
workflow_call:
inputs:
ref:
description: 'Version tag to deploy (v<x.y.z>)'
required: false
type: string
workflow_dispatch:
inputs:
ref:
description: 'Version tag to deploy (empty = the ref this run was started from)'
required: false
type: string
permissions:
contents: read
id-token: write
concurrency:
group: mcp-deploy
cancel-in-progress: false
jobs:
deploy:
if: vars.AWS_ROLE_ARN != ''
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- name: Log in to ECR
id: ecr
uses: aws-actions/amazon-ecr-login@v2
# Built from the monorepo root; the image never builds the docs
- name: Build and push the image
id: image
run: |
version="$(node -p "require('./apps/mcp/package.json').version")"
image="${{ steps.ecr.outputs.registry }}/${{ vars.MCP_ECR_REPOSITORY }}:${version}"
latest="${{ steps.ecr.outputs.registry }}/${{ vars.MCP_ECR_REPOSITORY }}:latest"
docker build --file apps/mcp/Dockerfile --tag "$image" --tag "$latest" .
docker push "$image"
docker push "$latest"
echo "image=$image" >> "$GITHUB_OUTPUT"
# The versioned tag stays in ECR for a rollback (point the service at it in the console)
- name: Deploy to App Runner
run: aws apprunner start-deployment --service-arn "${{ vars.MCP_APPRUNNER_SERVICE_ARN }}"
As CloudFront Functions
O Docusaurus gera cada rota como uma pasta com index.html. A função do site traduz /docs/intro/ para esse arquivo:
// TEMPLATE (AWS): CloudFront Function (viewer request) of the docs site distribution.
// Docusaurus writes each route as a folder with an index.html (/docs/intro/ → /docs/intro/index.html);
// S3 behind CloudFront does not resolve that by itself, so this function does.
function handler(event) {
var request = event.request
var uri = request.uri
if (uri.endsWith('/')) request.uri = uri + 'index.html'
else if (uri.split('/').pop().indexOf('.') === -1) request.uri = uri + '/index.html'
return request
}
A do corpus só deixa passar quem manda o cabeçalho certo. O valor esperado fica num KeyValueStore do CloudFront, não no código:
// TEMPLATE (AWS): CloudFront Function (viewer request, runtime cloudfront-js-2.0) of the corpus distribution.
// Only the MCP server may read ai-corpus.json: it sends CONTENT_AUTHORIZATION as the Authorization header, and this
// function compares it with the value kept in a CloudFront KeyValueStore (key "corpus-authorization"), so the secret
// never lives in the code. Associate the KeyValueStore with the function and put its id below.
import cf from 'cloudfront'
const kvs = cf.kvs('<KEY_VALUE_STORE_ID>')
async function handler(event) {
const expected = await kvs.get('corpus-authorization')
const received = event.request.headers.authorization && event.request.headers.authorization.value
if (!expected || received !== expected) return { statusCode: 401, statusDescription: 'Unauthorized' }
return event.request
}