5
votes

Below the screenshot, it seems to be successful only in one Availability Zone.

I checked the codedeploy logs for a failed instance, and I found that there was an error, I think it is recognized as an on-premise instance.

2018-01-10 04:40:22 INFO [codedeploy-agent(2696)]: On Premises config file does not exist or not readable

2018-01-10 04:40:43 ERROR [codedeploy-agent(2696)]: CodeDeploy Instance Agent Service: CodeDeploy Instance Agent Service: error during start or run: InstanceMetadata::InstanceMetadataError - Not an EC2 instance and region not provided in the environment variable AWS_REGION. Please specify your region using environment variable AWS_REGION.......

I've searched for about three days for this issue, but there was no mention in the AWS documentation. In the production env, I plan to use two Availability Zones attached to the auto scaling group. I wonder if I'm overlooking the other thing except CodeDeploy... What should I check? Thank you in advance.

[Updated] I update with ASG and ASG Config screent shot. There's no special, it's vanila and default process. I waiting 5 days from AWS support center but still pending response.

Auto Scaling Group ----- Auto Scaling Group

Auto Scaling Group Launch Config ----- Auto Scaling Group Launch Config

1
why don't you attach the ELB to codedeploy config instance of adding instances in two different instances ?Kush Vyas
@KushVyas I have already tested with the ELB + ASG combination, but it still fails to deploy if the availability zone is different. To simplify the question, I have configured the situation.coding8282
Can you try login to that ec2 and post the output of command curl http://169.254.169.254/latest/meta-dataRavi
@Ravi There seems to be a problem with that instance. When I enter 169.254.169.254, I can not connect. On the other hand, the meta-data was correctly seen on the instances that was successfully deployed. This seems to be the problem. Is the AMI of my ASG Launch Config a problem? My AMI is in ap-southeast-1a, so the instances in ap-southeast-1b seems to fail to deploy.coding8282
@hyunsu AMIs are different by region, not by AZ, so as long as you're using the same AMI, it should work.EmptyArsenal

1 Answers

3
votes

Finally, I found out why codedeploy failed across multiple availability zones on Windows 2016. Also, this problem seems to be an issue with Windows 2016 EC2 itself rather than ASG or codedeploy(I have not tested it on linux). There are 2 solutions I found,

  1. Shut down the server safely by clicking the button "Shutdown with Syspre" in Ec2LaunchSettings. And then you can create AMI as usal.

Ec2LaunchSetting GUI

  1. Run the C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule script manually. The argument "-Schedule" is required. And then you can create AMI as usal.

InitializeInstance.ps1

The first method is an intuitive and convenient way(GUI), and the second method is appropriate for automate a powershell script. I have confirmed that both methods succeed in deploying to multiple AZs. There were no errors in the logs recorded by codedeployagent.

To be more specific, codedeployagent leaves various logs at the time of deployment, and I found that the agent seems to use meta-info from 169.254.169.254. When I failed, the log say "You are On-Premise Instance.". Probably the deployment fails because the instance can not get meta-info. In the following document, I have received a lot of help and all of my solutions are listed.

https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2launch.html

Especially, in the document

.....In Windows PowerShell, run the following command so that the system schedules the script to run as a Windows Scheduled Task. The script runs one time during the next boot and then disables these tasks from running again....

C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule