This sample demonstrates how to create a full environment for the open source forum tool Discourse. This example will create all assets required to utilize AWS services. The Discourse site will be automatically setup with an initial admin user and an OpenID plugin is set up to allow users to register and login via Amazon Cognito.
- Amazon CloudFront is used for CDN via S3 and the application load balancer
- Amazon Route 53 holds the hosted zone for DNS management to create verified outbound email domains along with domain certificates
- Amazon S3 holds user upload files and static assets in one bucket along with Discourse backups in another bucket
- AWS Certificate Manager is used to create a DNS validated certificate
- AWS Secrets Manager holds the initial setup credentials and created database credentials.
- Amazon Cogntio user pools are used via OpenID
- Amazon SES handles outbound email notifications
- AWS Systems Manager Session Manager is used to connect to internal instances for debugging purposes
- AWS Auto Scaling will create the desired number of instances in the desired availability zones
- Amazon EC2 instances are bootstrapped via a user data script which pulls down the latest stable version of Discourse and sets up the app.yml then launches the Discourse docker image.
- Amazon RDS Aurora serverless V2 Postgres database stores user details and posts
- Amazon ElastiCache for Redis is used as a caching layer
- Apache Maven 3.8.5 or greater installed
- Java 11 or greater installed
- AWS Cloud Development Kit (CDK) 1.120.0 or higher
- Valid docker login credentials
- A domain name hosted by Route53 which is used to
- Create a subdomain for discourse
- Validate SES domain
- Validate DNS Certificates
- Public Acl creation must be enabled on the account for discourse to work. The following aws cli command will enable the required options
aws s3control put-public-access-block \
--account-id 123456789012 \
--public-access-block-configuration '{"BlockPublicAcls": false, "IgnorePublicAcls": true, "BlockPublicPolicy": true, "RestrictPublicBuckets": true}'
- Git clone this repository
- Create an AWS Secrets Manager secret with the following key value pairs
- DOCKER_USER - A docker login user (required for docker pull quota)
- DOCKER_PASSWORD - A docker login password
- DISCOURSE_ADMIN_EMAIL - The email address for the initial admin user
- DISCOURSE_ADMIN_PASSWORD - The password for the initial admin user
- DISCOURSE_ADMIN_USERNAME - The username for the initial discourse user
- Note this is a discourse login and is not linked to cognito.
- Edit the cdk-command.sh with information required
- CDK_DEPLOY_DISCOURSE_ACCOUNT - The AWS account used for this deployment
- CDK_DEPLOY_DISCOURSE_REGION - The AWS region used for this deployment
- CDK_DEPLOY_DISCOURSE_STACK_ID - The stack id can be modified to allow for CI/CD and multiple different deployments. If no value is set the default value of 'Discourse' is used.
- CDK_DEPLOY_DISCOURSE_HOSTED_ZONE_ID - The Route 53 hosted zone id
- CDK_DEPLOY_DISCOURSE_HOSTED_ZONE_NAME - The Route 53 hosted zone name
- CDK_DEPLOY_DISCOURSE_DOMAIN_NAME - The domain name to use for this instance of discourse for example 'discourse.example.com'
- CDK_DEPLOY_DISCOURSE_SES_SMTP_DOMAIN_NAME - The domain name to use for SES SMTP emails
- CDK_DEPLOY_DISCOURSE_NOTIFICATION_EMAIL - The email address for outbound notification emails from the Discourse system
- CDK_DEPLOY_DISCOURSE_DEVELOPER_EMAILS - A list of admin account email addresses separated by commas
- CDK_DEPLOY_DISCOURSE_COGNITO_AUTH_SUB_DOMAIN_NAME - Amazon Cognito domain for the hosted UI
- CDK_DEPLOY_DISCOURSE_SETTINGS_SECRET_ARN - 'arn:aws:secretsmanager:{region}:{account}:secret:{secret}
- CDK_DEPLOY_DISCOURSE_CIDR - The CIDR block to use when creating the VPC
- CDK_DEPLOY_DISCOURSE_CLOUDFRONT_ALB_HEADER_CHECK_HEADER - This header name is used to restrict access to the ALB from just CloudFront. If this environment variable is not found a default value of 'X-Discourse-ALB-Check' is used.
- CDK_DEPLOY_DISCOURSE_CLOUDFRONT_ALB_HEADER_CHECK_VALUE - The header value use to restrict access to the ALB from just CloudFront. If this environment variable is not found a default value of 'c9fd4d17-24a6-463f-b470-1c4347253245' is used.
- Run
./cdk-command.sh deploy
to deploy into your account - It takes approx. 15-20 minutes AFTER the discourse EC2 instance is created for the full discourse setup to complete and be available
- The EC2 instance will set up the database structure and push assets to the S3 bucket prior to starting up the Discourse server
- You can log into EC2 instances via Session Manager
- Once logged in you will require
sudo -s
for most commands - Discourse is installed in the folder
/var/discourse
- Running
. discourse-env
in the/var/discourse
folder will set up the current shell session environment variables - To check if docker is running execute the command
docker ps
- EC2 instance startup logs are located at
/var/log/cloud-init-output.log
and can be helpful to determine the actions taken by the user data startup script.- This log may also contain any errors that occurred on startup.
- You can run various docker commands via the Discourse helper script
./launcher {command} app
for instance:./launcher enter app
will put you into the discourse docker instance shell./launcher logs app
will display the discourse docker app logs
- Your accounts SES (simple email service) will only send email to verified addresses unless validated for production.
- Via the console you can add your own email to the verified list for testing
- From the root folder for this project run
./cdk-command.sh destroy
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.