- Choose Amazon Linux 2 AMI (HVM) - Kernel 5.10, SSD Volume Type as your machine image
- Choose t2.micro (Free tier eligible) for instance type
- Under Configure Instance Details, select the previously created IAM Role.
- Under Configure Security Group, Allow incoming access to:
| Type | Port Range | Description. |
|---|---|---|
| SSH | 22 | Port for SSH into server |
| HTTP | 80 | Port for HTTP requests to web server |
| HTTPS | 443 | Port for HTTPS requests to web server |
| Custom TCP | 5000 | Port for API |
- Finally, launch the instance and create a new key pair and store it in a secure and accessible location. (This will generate a .pem key which is used for SSH)
- Locate your EC2 Instance under Instances on the EC2 page.
- Locate your Public IPv4 DNS, and SSH into it using your .pem key (ssh -i "file.pem" ec2-user@xxxxxxxx.compute-1.amazonaws.com
After ssh, run the following commands:
Update package management tool
$ sudo yum updateInstall CodeDeploy Agent (locate your region first)
$ sudo yum install -y ruby
$ sudo yum install wget
$ wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
$ chmod +x ./install
$ sudo ./install auto
$ sudo systemctl start codedeploy-agentInstall nginx
$ sudo yum install nginxInstall Nodejs
$ sudo yum install nodejsInstall dotnet environment
run the following commands to add the Microsoft package signing key to your list of trusted keys and add the Microsoft package repository.
$ sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpmTo install the .NET SDK, run the following command:
$ sudo yum install dotnet-sdk-6.0Install pm2
$ sudo npm install -g pm2-
Choose Standard create for creation method
-
Choose PostgreSQL for Engine type and 12.9-R1 for Version under Engine options
-
Select Free tier for template
-
Create and store username and password credentials (will be used in connection string)
-
Turn Public access off and choose the same virtual private cloud the EC2 instance is on
-
For authentication options, select Password authentication.
-
To allow communication between API and database:
- Go to EC2 console and under security groups add the database's and EC2's security groups to eachothers inbound and outbound rules.
-
To add connection string to EC2 environment,
- SSH into EC2 server
- cd into the api folder and create appsettings.Production.json file with the connection string using vim.
- Create an application
- Create a deployment group
- For the environment configuration, choose Amazon EC2 instances, and choose the tag for your EC2 instance.
- Create and add appspec.yml to github repo to manage deployment
- Create new pipeline and select new service role
- Select Github (Version 2) for source provider and add the github repository.
- Choose Start the pipeline on source code change for Change detection options.
- Choose CodePipeline default for Output artifact format.
- Choose AWS CodeBuild for Build provider
- Create a new build project
- Choose Managed image for Environment image and Amazon Linux 2 for Operating System.
- Select Standard Runtime and aws/codebuild/amazonlinux2-x86_64-standard:3.0 for image.
- Choose aws/codebuild/amazonlinux2-x86_64-standard:3.0-21.10.15 for image version and Linux for Environment type.
- Select New service role for Service role.
- Create and add buildspec.yml to github repo and put its path for the Build specifications name.
- Continue to CodePipeline
- For Deploy provider, select AWS CodeDeploy and choose the previously created application and deployment group.