Skip to content

Instantly share code, notes, and snippets.

@adityaprakash-bobby
Last active February 29, 2020 08:35
Show Gist options
  • Save adityaprakash-bobby/eff11b3201d759071d5b006a0f4b2271 to your computer and use it in GitHub Desktop.
Save adityaprakash-bobby/eff11b3201d759071d5b006a0f4b2271 to your computer and use it in GitHub Desktop.
ECS - 404 with apache && 502 with ALB
FROM ubuntu:18.04
RUN apt-get update && \
apt-get -y install apache2
RUN echo 'Hello World!' > /var/www/html/index.html
# Configure apache
RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \
echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \
chmod 755 /root/run_apache.sh
EXPOSE 80
CMD /root/run_apache.sh
  1. Create VPC with one public and one private subnet
  2. Configure routes for private subnet and public subnet
  3. Create 3 security groups - for EC2 Container Instances to be hit by loadbalancer, a security group from the application load balancer, another for the ECS Cluster
  4. Create a target group with target type as IP with default health check settings.
  5. Create application load balancer in the above in the VPC with the preconfigured target groups, security groups.
  6. Create an ECS cluster with the above configurations
  7. Launch 2 instances (here, one t2.micro, one t2.large) with ECS optimized Amazon AMI 2 and configure the ecs.config file to point to the above created ECS cluster.
  8. Build the docker container image in one of the EC2 instances and push it to the ECR.
  9. Create task definitions with the above docker conatiner image.
  10. Create a service with 2 tasks of replica type in EC2 launch type and add the above created ALB and target group to its configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment