Skip to content

Install Code Deploy Agent on Linux EC2 Instance in Automated Way

0

Hi everyone. I have tried to add a User Data to my instance and add commands so it would automatically install the Code Deploy Agent on my Instance but not working as expected.

I have tried this resolution to but nothing happens https://repost.aws/knowledge-center/codedeploy-agent-launch-template

Is there other way around on which my instance would have a Code Deploy Agent whenever created. Thank you!

1 Answer
1

Hello.

What OS are you using on your EC2 instance?
For Amazon Linux 2023, if you set the following command in the user data, it will be installed when EC2 is created.
Change "<your-region-code>" to the region where you want to launch EC2.
https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-linux.html

#!/bin/bash
yum update
yum install ruby -y
yum install wget -y
wget https://aws-codedeploy-ap-northeast-1.s3.<your-region-code>.amazonaws.com/latest/install
cd
chmod +x ./install
./install auto
service codedeploy-agent start
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
EXPERT
reviewed 2 years ago
  • I have added this on my cloudformation script since I am creating an immutable server and whenever instance has been created I need to install the cloud deploy agent. But the deploy events was failed in the first process which is "Application Stop"

  • Hi Riku, I am using Ubuntu and Debian OS

  • For Ubuntu, try using the user data below. Please change "<your-region-code>" to the region you are using on EC2.

    #!/bin/bash
    apt update
    apt install ruby-full -y
    apt install wget -y
    cd
    wget https://aws-codedeploy-<your-region-code>.s3.<your-region-code>.amazonaws.com/latest/install
    chmod +x ./install
    ./install auto
    systemctl start codedeploy-agent
    
  • Currently getting this error for running sudo apt update

    Err:1 https://download.newrelic.com/infrastructure_agent/linux/apt focal InRelease Could not connect to download.newrelic.com:443 (199.232.46.137), connection timed out Unable to connect to download.newrelic.com:https: Err:2 https://deb.nodesource.com/node_16.x focal InRelease Cannot initiate the connection to deb.nodesource.com:443 (2606:4700:10::ac43:acd). - connect (101: Network is unreachable) Cannot initiate the connection to deb.nodesource.com:443 (2606:4700:10::6816:51a). - connect (101: Network is unreachable) Cannot initiate the connection to deb.nodesource.com:443 (2606:4700:10::6816:41a). - connect (101: Network is unreachable) Could not connect to deb.nodesource.com:443 (104.22.4.26), connection timed out Could not connect to deb.nodesource.com:443 (172.67.10.205), connection timed out Could not connect to deb.nodesource.com:443 (104.22.5.26), connection timedout Err:3 https://apt.datadoghq.com stable InRelease Cannot initiate the connection to apt.datadoghq.com:443 (2600:9000:229f:1600:e:4acf:9bc0:93a1). - connect (101: Network is unreachable) Cannot initiate the connection to apt.datadoghq.com:443 (2600:9000:229f:f200:e:4acf:9bc0:93a1). - connect (101: Network is unreachable) Cannot initiate the connection to apt.datadoghq.com:443 (2600:9000:229f:4e00:e:4acf:9bc0:93a1). - connect (101: Network is unreachable) Cannot initiate the connection to apt.datadoghq.com:443 (2600:9000:229f:ae00:e:4acf:9bc0:93

  • It seems that I am not able to access the remote repository from EC2 properly. Is the route table configured to access the Internet from the EC2 instance? For example, if you are running EC2 in a private subnet, you will need to set up a NAT Gateway and register it as a default route in the subnet's route table.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.