An example of how to bring up a highly available dotnet core application on AWS using - in this example; Terraform, CentOS 7, AWS ELB, AWS EC2, AWS Aurora Cluster (mysql) and dotnet core 2.1 for Linux
- Download terraform (https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_windows_amd64.zip), make sure its in %PATH%
- Download git - https://github.com/git-for-windows/git/releases/download/v2.20.1.windows.1/Git-2.20.1-64-bit.exe
- Download AWS CLI - https://s3.amazonaws.com/aws-cli/AWSCLI64PY3.msi
- Run ‘aws configure’ to configure AWS credentials - in this example we use "us-east-1" but it is "hardcoded" in terraform
- Create c:\source (or whatever you want)
- Open git bash, go to /c/source/ and run ‘git clone https://github.com/glarsson/glarssonaws.git’
- Create keys; in git bash create the ssh keys for the environments in the following directories:
/c/source/glarssonaws/terraform/test/keys/ /c/source/glarssonaws/terraform/staging/keys/ /c/source/glarssonaws/terraform/production/keys/ to create key run command in git bash: ssh-keygen -t rsa -b 4096 -C "[email protected]" name the key "ENVIRONMENT_key" - so for each it will be "test_key", "staging_key" and "production_key".
- In each terraform environment, create "secret_variables.tf", this file will contain the username and password for your aurora cluster root user:
c:\source\glarssonaws\terraform\test\secret_variables.tf c:\source\glarssonaws\terraform\staging\secret_variables.tf c:\source\glarssonaws\terraform\production\secret_variables.tf contents of that file: variable "rds_master_username" { default = "whatever_username_you_want" } variable "rds_master_password" { default = "whatever_password_you_want" }
- If you want to debug/run/develop the dotnet core application locally you need to add "appsettings.json" in glarssonaws/dotnet_core_application/dotnet_core_application/ - of course you need a local mysql server for this..
{ "Logging": { "LogLevel": { "Default": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "server=MYSQL_SERVER;userid=MYSQL_USERNAME;password=MYSQL_PASSWORD;database=glarssonaws_db;" } }
- Go to c:\source\glarssonaws\terraform\test
- Run command "terraform init"
- Run command "terraform plan" to prepare terraform to take action
- Finally run command "terraform apply" and make sure you answer "yes" if you agree with the changes it proposes
- Go to c:\source\glarssonaws\terraform\staging
- Run command "terraform init"
- Run command "terraform plan" to prepare terraform to take action
- Finally run command "terraform apply" and make sure you answer "yes" if you agree with the changes it proposes
- Production doesn't exist, you can look at staging as the same as production. It was not developed here because of cost and time saving reasons. Every time these environments are brought up there is a cost and it takes ~25-30 minutes, test is a bit quicker.
- Go to c:\source\glarssonaws\terraform\test
- Run command "terraform destroy" and make sure you answer "yes" to confirm
- Go to c:\source\glarssonaws\terraform\staging
- Run command "terraform destroy" and make sure you answer "yes" to confirm