- TypeScript 100%
pds-cdk #
AWS CDK app that provisions the infrastructure to host a self-managed Bluesky PDS on a single EC2 instance.
The stack only provisions infrastructure — installing the PDS itself is left to the official install script, which is run on the box after the stack is up.
What it builds #
- VPC — single public subnet, no NAT gateway.
- EC2 instance — Ubuntu 24.04 LTS (ARM64),
t4g.smallby default, with a 100 GB encrypted gp3 root volume. The Canonical AMI ships with the SSM agent preinstalled, so the box is reachable via Session Manager without an SSH key. IMDSv2 is enforced and termination protection is on. - Elastic IP — associated with the instance so the PDS hostname has a stable address.
- Security group — 80/443 open to the world (HTTPS plus the Let's Encrypt ACME challenge), 22 optionally open to a CIDR you specify.
- S3 blob bucket — backs
PDS_BLOBSTORE_S3_BUCKET. Versioned, encrypted, no public access; CORS scoped to the PDS domain. - S3 Litestream bucket — destination for SQLite backups, per the Going to Production guide.
- KMS key —
ECC_SECG_P256K1SIGN_VERIFY key forPDS_PLC_ROTATION_KEY_KMS_KEY_ID. - Route53 public hosted zone — apex
Arecord + wildcardArecord (so account handles likealice.pds.example.comresolve) pointing at the EIP. - IAM instance profile — read/write on both buckets,
kms:Sign/GetPublicKey/DescribeKeyon the rotation key, and theAmazonSSMManagedInstanceCoremanaged policy.
Layout #
pds-cdk/
├── bin/cdk.ts # app entrypoint, stack instantiation
├── lib/pds-stack.ts # the stack
├── cdk.json
├── package.json
└── tsconfig.json
Prerequisites #
- Node 20+ and
pnpm - AWS credentials in your shell (
AWS_PROFILEor env vars) CDK_DEFAULT_ACCOUNTandCDK_DEFAULT_REGIONset- The target account must be
cdk bootstrap'd in the chosen region.
Configuration #
pdsDomainName is required and is passed via CDK context — must be a domain
you control. Route53 will become the authoritative hosted zone for it, and
you'll need to delegate the NS records at your registrar after the first
deploy.
pnpm cdk deploy -c pdsDomainName=pds.example.com --profile pds
Optional PdsStack props (set in bin/cdk.ts if you want to change defaults):
sshAllowedCidr— if set, opens port 22 to that CIDR. Omit to keep SSH closed and use SSM Session Manager.instanceType— defaults tot4g.small.rootVolumeSizeGb— defaults to 100.
The Ubuntu AMI is pinned to a specific dated SSM parameter
(UBUNTU_AMI_SSM_PARAM in lib/pds-stack.ts). To roll the OS image, find a
newer dated entry and edit the constant:
aws ssm get-parameters-by-path \
--path "/aws/service/canonical/ubuntu/server/24.04/stable" \
--recursive \
--query "Parameters[?ends_with(Name, '/arm64/hvm/ebs-gp3/ami-id')].Name" \
--output text | tr '\t' '\n' | sort -u | tail
Bumping the date is a deliberate code change — it will cause CloudFormation to replace the EC2 instance on the next deploy. (Termination protection is on, so you'll need to disable it first or take it down via the console.) Canonical prunes very old dated entries; if the pinned date eventually disappears, look up a current one with the command above.
Deploying #
Replace pds with whatever AWS profile name you use locally and
pds.example.com with your domain.
pnpm install
# One-time per account/region: provision the CDK bootstrap stack.
pnpm cdk bootstrap --profile pds
# Sanity check — synthesizes to cdk.out without deploying.
pnpm build -c pdsDomainName=pds.example.com
# Deploy. CDK will print an IAM/security-group diff and prompt for approval.
pnpm cdk deploy -c pdsDomainName=pds.example.com --profile pds
Stack outputs include the EIP, blob bucket name, Litestream bucket name, KMS key ID, and the hosted zone nameservers. After the first deploy:
- Delegate
pdsDomainNameto the four nameservers fromPdsHostedZoneNameserversat your registrar. - Connect to the box (
aws ssm start-session --target <PdsInstanceId>). - Run the official PDS install script from the bluesky-social/pds repo.
- In
pds.env, wire the stack outputs in:PDS_BLOBSTORE_S3_BUCKET=<PdsBlobstoreBucket>PDS_BLOBSTORE_S3_REGION=<your region>PDS_PLC_ROTATION_KEY_KMS_KEY_ID=<PdsPlcRotationKeyId>- Set
PDS_SQLITE_DISABLE_WAL_AUTO_CHECKPOINT=trueand configure Litestream to ship/pds/actors/*.sqliteto the Litestream bucket. - Generate and safely store
PDS_RECOVERY_DID_KEYseparately — the corresponding private key is your last-resort recovery if the KMS key is ever lost.
TODO #
- Replace Let's Encrypt with AWS-native TLS. The default PDS install relies
on Caddy on the box for ACME. That works, but it puts cert renewal on a
single instance and requires keeping port 80 open. Worth investigating
whether to terminate TLS at an ALB/NLB with an ACM certificate instead, or
front the PDS with CloudFront. Both shift renewal to AWS but add cost and
complexity (and CloudFront in particular needs careful handling for the
WebSocket firehose endpoint at
/xrpc/com.atproto.sync.subscribeRepos).