EC2 with Autoscaling group

Use the Application Load Balancer to make the EC2 instance redundant. You can also set up autoscaling on an EC2 instance to increase or decrease the number of EC2 instances at a fixed time.

Terraform Code (Github)

Environment

  • VPC
  • Two public subnets.
  • Up to two EC2 instances Auto-scaling management
  • ELB (Application Load Balancer)

EC2

  • OS: Ubuntu 18.04
  • Nginx is installed on EC2 and is accessible via ALB at https://FQDN
  • You can access to Nginx via SSH.
    • The public key file for SSH access is specified with the variable “pubkey_file_path”.
  • Install and start Nginx with user data.
  • Register the instance to Autoscaling Group.
  • Set up a scaling policy to start the instance at 4:00 AM and stop the instance at 21:00 PM on weekdays.

ELB

  • Creates an Application Load Balancer.
  • It supports HTTP and HTTPS.
  • A server certificate is required for HTTPS communication. Please prepare for this by referring to the procedure for issuing a certificate in ACM.
  • Save the ELB access log to the S3 bucket.

ACM Certificate