Deploy Containerized Apache Application on ECS Using ECR
Step-by-step guide on deploying a containerised Apache application using Amazon ECS using ECR
Published Aug 13, 2024
Last Modified Aug 20, 2024
1.Create ECR Repository for ECS Container
Go to Amazon Elastic Container Registry and click "Create repository"
Select "Private" and provide the repository name
Click "Create repository"
2. Create an IAM user with ECR permissions
Go to IAM and click "Create user"
Provide a username
Add the user to the admin group. Here, you can also restrict access with a custom policy
Click "Create user"
Go to the new user and create an Access key for AWS CLI
Select "Command line interface (CLI)"
Enter a description for the access key and click “create access key”
Copy the access key and secret key, as the secret key value will not be visible again
To verify if AWS CLI is installed and available on your system, you can run the following command in your terminal or command prompt. If AWS CLI is installed, this command will display the version information. If it is not installed, you'll receive an error message indicating that the command is not recognized
To configure AWS CLI with your access credentials
You'll be prompted to enter the following details:
- AWS Access Key ID: Enter your access key.
- AWS Secret Access Key: Enter your secret key.
- Default region name: Enter your preferred AWS region (e.g., us-west-2).
- Default output format: Enter your preferred output format (e.g., Json, text, or yaml).
Verify the configuration
3. Build the Docker image and push it to ECR
Create a Dockerfile to build a Docker image
Build docker image using this command (docker build -t devopstronaut .)
Retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI
Tag your image so you can push the image to this repository
Run the following command to push this image to your newly created AWS repository
Verify that the docker image has been pushed
4.Create ECS Cluster
Go to AWS ECS and click “Create Cluster”
Enter a cluster name and choose "AWS Fargate" so that the cluster is automatically configured for AWS Fargate
The Cluster has been created successfully
Create Task definition
Specify the task definition family and set the launch type to "AWS Fargate"
Enter the container name, provide the ECR image URI, and specify the port name
You can verify the created task by checking the container name
Create ECS Service
Go back to the "Deploy" section and select "Create service"
Choose the existing cluster and select compute option as “capacity provider”
Provide the Service name and specify the desired tasks to “1”
In the Networking section, choose the VPC, subnet, and security group
It will take more time to create the service
Verify the task status after the service has been created
Go to Tasks configuration and Copy the Public IP Address from Task
Paste the IP address to the browser and now you should be able to access the Apache website from AWS ECS.
Keep Learning, Keep Automating!!!
Feel free to reach out to me, if you have any other queries or suggestions
Stay connected on Linkedin https://www.linkedin.com/in/mahendran-selvakumar-36444a77/
Stay connected on Medium https://devopstronaut.com/