Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/deploy-template-to-s3-bucket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Deploy CloudFormation Template to S3

on:
push:
branches:
- main
paths:
- 'infrastructure/templates/cloudfront.yaml'
- 'infrastructure/templates/remove-cloudfront.yaml'

workflow_dispatch:

jobs:
deploy-template:
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}

- name: Upload CloudFormation templates to S3
run: |
echo "Uploading CloudFront template to s3://${{ vars.S3_BUCKET }}/${{ vars.S3_FILE_KEY }}"
aws s3 cp infrastructure/templates/cloudfront.yaml s3://${{ vars.S3_BUCKET }}/${{ vars.S3_FILE_KEY }}

echo "Uploading cleanup template to s3://${{ vars.S3_BUCKET }}/remove-cloudfront.yaml"
aws s3 cp infrastructure/templates/remove-cloudfront.yaml s3://${{ vars.S3_BUCKET }}/remove-cloudfront.yaml

# Verify uploads
echo "Verifying template accessibility..."
curl -f -I https://${{ vars.S3_BUCKET }}.s3.amazonaws.com/${{ vars.S3_FILE_KEY }}
curl -f -I https://${{ vars.S3_BUCKET }}.s3.amazonaws.com/remove-cloudfront.yaml

echo "✅ Templates successfully deployed!"
echo "CloudFront Template URL: https://${{ vars.S3_BUCKET }}.s3.amazonaws.com/${{ vars.S3_FILE_KEY }}"
echo "Cleanup Template URL: https://${{ vars.S3_BUCKET }}.s3.amazonaws.com/remove-cloudfront.yaml"

- name: Update deployment status
run: |
echo "::notice title=Templates Deployed::CloudFormation templates updated - CloudFront: https://${{ vars.S3_BUCKET }}.s3.amazonaws.com/${{ vars.S3_FILE_KEY }}, Cleanup: https://${{ vars.S3_BUCKET }}.s3.amazonaws.com/remove-cloudfront.yaml"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.scratch
.scratch/
116 changes: 58 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,31 @@ aws sts get-caller-identity
aws sso login --profile YOUR-PROFILE
```

## 🚀 One-Click Deploy

Deploy the CloudFront reverse proxy directly from the AWS Console with pre-configured settings.

| Region | Launch Stack | Console Link |
|--------|--------------|--------------|
| **US East (N. Virginia)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) |
| **US East (Ohio)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) |
| **US West (Oregon)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) |
| **EU West (Ireland)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml&stackName=ld-cloudfront-proxy&param_UseCustomDomain=false&param_PriceClass=PriceClass_100&param_EnableLogging=false) |

You can deploy to any AWS region by changing `region=us-east-1` in the URL to your preferred region (e.g., `region=ap-southeast-1`).

**Template URL:** `https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/cloudfront.yaml`

The template is automatically updated via GitHub Actions when changes are merged to main for `infrastructure/cloudfront.yaml`

## Configuration Options

| Parameter | Default | Options | Description |
|-----------|---------|---------|-------------|
| `UseCustomDomain` | `false` | `true`/`false` | Use your own domain instead of CloudFront default |
| `DomainName` | `""` | Your domain | Required if UseCustomDomain=true (e.g., `flags.my-super-awesome-company.com`) |
| `DomainName` | `""` | Your domain | Required if UseCustomDomain=true (e.g., `flags.my-company.com`) currently we only support one sub-domain |
| `AcmCertificateArn` | `""` | ACM ARN | Required if UseCustomDomain=true (must be in us-east-1) |
| `AutoCreateDNS` | `false` | `true`/`false` | **NEW:** Automatically create Route 53 DNS record |
| `AutoCreateDNS` | `false` | `true`/`false` | Automatically create Route 53 DNS record |
| `HostedZoneId` | `""` | Route 53 Zone ID | Required if AutoCreateDNS=true (e.g., `Z1D633PJN98FT9`) |
| `PriceClass` | `PriceClass_100` | `PriceClass_100`/`200`/`All` | Coverage: US/Canada/Europe/Asia (100) vs Global (All) |
| `EnableLogging` | `false` | `true`/`false` | Enable CloudFront access logging |
Expand All @@ -40,70 +57,22 @@ aws sso login --profile YOUR-PROFILE
- **PriceClass_200**: Adds Middle East, Africa - Medium cost
- **PriceClass_All**: Global coverage - Highest cost

### Custom Domain Setup Options

**⚠️ PREREQUISITES:** Before using `UseCustomDomain=true`, you must complete the following setup!!

#### Step 1: Get Your Route 53 Hosted Zone ID
```bash
# Find your hosted zone ID (replace with your domain)
aws route53 list-hosted-zones --query 'HostedZones[?Name==`my-awesome-domain.com.`].[Id,Name]' --output table

# Example output: Zone ID like Z01741713N143BEH1HBBD
```

#### Step 2: Create ACM Certificate (Required)
```bash
# Request SSL certificate (MUST be in us-east-1 for CloudFront)
aws acm request-certificate \
--domain-name flags.my-awesoome-domain.com \
--validation-method DNS \
--region us-east-1

# Save the Certificate ARN from the output!
```

#### Step 3: Validate Certificate
```bash
# Get DNS validation record details
aws acm describe-certificate --certificate-arn YOUR-CERT-ARN --region us-east-1

# Create validation record in Route 53 (replace with your values)
aws route53 change-resource-record-sets --hosted-zone-id YOUR-ZONE-ID --change-batch '{
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "_validation-string.flags.my-awesome-domain.com.",
"Type": "CNAME",
"TTL": 300,
"ResourceRecords": [{"Value": "_validation-value.acm-validations.aws."}]
}
}]
}'

# Verify certificate is issued...this will take a few minutes
aws acm describe-certificate --certificate-arn YOUR-CERT-ARN --region us-east-1 \
--query 'Certificate.Status' --output text
# Should return: ISSUED
```

Once validated, proceed to Option 1 for deployment. If you are not using a custom domain, use Option 2 for deployment.

### Option 1: AWS CloudFront Reverse proxy with Custom DNS

**Deployment time:** ~15-20 minutes (CloudFront global propagation)

If you have a Route 53 hosted zone, the template can automatically create DNS records.
If you have a Route 53 hosted zone, the template can automatically create the certificate and DNS records. Ensure you already have the hosted zone setup.

NOTE: Ensure you have followed the above steps in the Custom Domain Setup Options section prior to running the below command.

```bash
aws cloudformation deploy \
--template-file templates/cloudfront.yaml \
--stack-name ld-cloudfront-proxy \
--parameter-overrides \
UseCustomDomain=true \
DomainName=flags.my-awesome-domain.com \
DomainName=flags.my-company-domain.com \
AcmCertificateArn=my-awesome-arn \
AutoCreateDNS=true \
HostedZoneId=my-awesome-hosted-zone-id \
Expand All @@ -120,7 +89,7 @@ aws cloudformation describe-stacks \
--output table
```

This will return your CloudFront domain (e.g., `flags.my-awesome-domain.com`)
This will return your CloudFront domain (e.g., `flags.my-company-domain.com`)


### Option 2: AWS CloudFront Reverse proxy with generic DNS
Expand Down Expand Up @@ -150,7 +119,7 @@ aws cloudformation describe-stacks \

This will return your CloudFront domain: `d4a2b1c1d5e6f9.cloudfront.net`

## 📱 SDK Configuration
## SDK Configuration

Once deployed, configure your LaunchDarkly SDKs to use your CloudFront proxy by specifying the options with the reverse proxy URL.

Expand All @@ -163,14 +132,14 @@ const LDProvider = await asyncWithLDProvider({
key: "unique-device-id"
},
options: {
baseUrl: 'https://flags.my-awesome-domain.com',
eventsUrl: 'https://flags.my-awesome-domain.com',
streamUrl: 'https://flags.my-awesome-domain.com'
baseUrl: 'https://flags.my-company-domain.com',
eventsUrl: 'https://flags.my-company-domain.com',
streamUrl: 'https://flags.my-company-domain.com
}
});
```

You may need to restart your application.
NOTE: You may need to restart your application.

## What Gets Deployed

Expand Down Expand Up @@ -245,3 +214,34 @@ Different LaunchDarkly projects within the same organization can use different c
- **Project C**: Uses a different proxy or region

Each project configures its SDK independently using different SDK keys and base URLs.

## Github Actions: Automated Template Deployment to s3 bucket

This repository includes a GitHub Actions workflow that automatically updates the S3-hosted CloudFormation templates when changes are merged to main.

## One-Click Cleanup

Remove your CloudFront proxy deployment and clean up all associated resources including DNS records and certificates.

### Cleanup Options

| Region | Launch Cleanup Stack | Console Link |
|--------|---------------------|--------------|
| **US East (N. Virginia)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) |
| **US East (Ohio)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) |
| **US West (Oregon)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) |
| **EU West (Ireland)** | [![Launch Stack](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) | [Text Link](https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/create/review?templateURL=https://ld-cloudfront-proxy-templates-09-25-25.s3.amazonaws.com/remove-cloudfront.yaml&stackName=cleanup-ld-cloudfront&param_StackNameToDelete=ld-cloudfront-proxy&param_CleanupDNS=true&param_CleanupCertificate=true) |

### Required Parameters

Before clicking cleanup, you'll need to provide:

- **StackNameToDelete**: Name of your CloudFront stack (default: `ld-cloudfront-proxy`)
- **DomainName**: Your custom domain (e.g., `flags.your-company.com`) - leave empty to skip DNS/cert cleanup
- **CleanupDNS**: Set to `true` to remove Route 53 DNS records
- **CleanupCertificate**: Set to `true` to remove ACM certificates

> **⚠️ Warning:** This will permanently delete your CloudFront proxy and all associated resources. Make sure you're ready before proceeding!

---

Loading