AWS CodeDeploy is a server software deployment service. It is different from traditional CI/CD deployment in the following ways:
- The server actively obtains files and deploys them.
- There is no need to open SSH for CI/CD service to connect to the operation.
AWS side settings
In addition to the CodeDeploy settings, you will also need to create an S3 bucket:
aws --profile default --region us-east-1 deploy create-application --application-name my-test
aws --profile default --region us-east-1 s3 mb "s3://gslin-codedeploy-us-east-1-my-test/"
Server-side Installation
An agent needs to be installed on the server side. This agent is responsible for obtaining files and executing the configured steps [1] .
Taking Ubuntu as an example [2] , you will need to first install Ruby 2.0 (under 14.04) or Ruby 2.3 (under 16.04), then obtain the installation configuration file and execute:
sudo apt -y install ruby
cd /tmp
wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install
chmod 755 install
sudo ./install auto
It may take longer to run on a non- EC2169.254.169.254
machine (you need to wait for the timeout; in an EC2 environment, this IP will have an HTTP service to provide information to the Instance).
Then check whether the Agent is started:
sudo service codedeploy-agent status
If not, you can start
start it with:
sudo service codedeploy-agent start
Additional steps for external machines
When the machine is not on EC2 , there are several ways to register it with the CodeDeploy system, which is called an On-Premises Instance. The method we introduce here is a method of giving a machine to an IAM user.
First, generate the corresponding permissions and configuration files on a general machine (not on the machine that needs to be registered), because to create IAM permissions, it is usually created by the administrator ( AdministratorAccess
some people):
aws deploy register --instance-name api-example-1 --region us-east-1
Then transfer the generated .yml
file to the machine to be registered:
scp codedeploy.onpremises.yml api-example-1:/tmp/
Then execute on the machine to be registered aws deploy install
:
cd /tmp
sudo aws deploy install --config-file codedeploy.onpremises.yml --region us-east-1
The above command will currently ruby2.0
display an error message because it wants to install but the system does not have it, but we have already installed the CodeDeploy file, the purpose of this command is just to insert its configuration file into the system.
If you http://169.254.169.254/
run it on some VPS that provides services (such as Vultr), there will be Amazon EC2 instances are not supported.
this kind of error message. At this time, you need to use iptables to temporarily block the connection to Port 80 of 169.254.169.254. In theory, this command will be invalid after restarting, and it will have no side effects on other applications:
sudo iptables -I OUTPUT -d 169 .254.169.254 -p tcp --dport 80 -j DROP
After everything is running (it is recommended to restart the machine directly for testing), remember to add a tag so that subsequent settings can capture the machine:
aws deploy add-tags-to-on-premises-instances --instance-name api-example-1 --tags Key = Name,Value = api-example-1