From 33da28e7caae7a5ef389260b36a4d8fdd4752cf7 Mon Sep 17 00:00:00 2001 From: Michael Haken Date: Thu, 13 Feb 2025 14:25:11 -0500 Subject: [PATCH] removing ec2 again --- cdk/Configs/cw-agent-config.json | 13 ++++++--- cdk/MultiAZWorkshopStack.cs | 2 +- cdk/NestedStacks/EC2FleetStack.cs | 44 +++++++++++-------------------- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/cdk/Configs/cw-agent-config.json b/cdk/Configs/cw-agent-config.json index 25452a6..bac4349 100644 --- a/cdk/Configs/cw-agent-config.json +++ b/cdk/Configs/cw-agent-config.json @@ -45,29 +45,34 @@ { "file_path": "/var/log/cfn-init-cmd.log", "log_group_name": "cfn-init-cmd.log", - "log_stream_name": "${aws:InstanceId}", + "log_stream_name": "{instance_id}", "timestamp_format": "%H: %M: %S%y%b%-d" }, { "file_path": "/var/log/cfn-init.log", "log_group_name": "cfn-init.log", - "log_stream_name": "${aws:InstanceId}", + "log_stream_name": "{instance_id}", "timestamp_format": "%H: %M: %S%y%b%-d" }, { "file_path": "/var/log/cloud-init-output.log", "log_group_name": "cloud-init-output.log", - "log_stream_name": "${aws:InstanceId}", + "log_stream_name": "{instance_id}", "timestamp_format": "%H: %M: %S%y%b%-d" }, { "file_path": "/var/log/cloud-init.log", "log_group_name": "cloud-init.log", - "log_stream_name": "${aws:InstanceId}", + "log_stream_name": "{instance_id}", "timestamp_format": "%H: %M: %S%y%b%-d" } ] } } + }, + "traces": { + "traces_collected": { + "xray": {} + } } } \ No newline at end of file diff --git a/cdk/MultiAZWorkshopStack.cs b/cdk/MultiAZWorkshopStack.cs index 61f8410..418d88f 100644 --- a/cdk/MultiAZWorkshopStack.cs +++ b/cdk/MultiAZWorkshopStack.cs @@ -160,7 +160,7 @@ public MultiAZWorkshopStack(App scope, string id, StackProps props) : base(scope albSecurityGroup.AddIngressRule(Peer.Ipv6(Fn.Select(0, this.NetworkStack.Vpc.VpcIpv6CidrBlocks)), Port.Tcp(80)); } - bool installEC2 = true; + bool installEC2 = false; if (installEC2) { diff --git a/cdk/NestedStacks/EC2FleetStack.cs b/cdk/NestedStacks/EC2FleetStack.cs index 409e2dc..4cb9089 100644 --- a/cdk/NestedStacks/EC2FleetStack.cs +++ b/cdk/NestedStacks/EC2FleetStack.cs @@ -67,8 +67,6 @@ public class EC2FleetStack : NestedStack "04_install-cloudwatch-agent", "05_config-amazon-cloudwatch-agent", "06_restart-amazon-cloudwatch-agent", - "07_xray-daemon-download", - "08_xray-daemon-install", "10_setup-firewalld", "13_install_icu_support", "14_set_database_details", @@ -492,43 +490,31 @@ string cwAgentConfigParameterName { "04_install-cloudwatch-agent", new InitConfig(new InitElement[] { - InitCommand.ShellCommand(Fn.Sub("rpm --upgrade --force -v -h https://s3.${AWS::Region}.${AWS::URLSuffix}/amazoncloudwatch-agent-${AWS::Region}/amazon_linux/${arch}/latest/amazon-cloudwatch-agent.rpm", new Dictionary(){ { "arch", props.CpuArch == InstanceArchitecture.ARM_64 ? "arm64" : "amd64" } })) - }) + // InitCommand.ShellCommand(Fn.Sub("rpm --upgrade --force -v -h https://s3.${AWS::Region}.${AWS::URLSuffix}/amazoncloudwatch-agent-${AWS::Region}/amazon_linux/${arch}/latest/amazon-cloudwatch-agent.rpm", new Dictionary(){ { "arch", props.CpuArch == InstanceArchitecture.ARM_64 ? "arm64" : "amd64" } })) + InitPackage.Yum("amazon-cloudwatch-agent") + }) + }, { "05_config-amazon-cloudwatch-agent", new InitConfig(new InitElement[] { - InitFile.FromString("/opt/aws/amazon-cloudwatch-agent/etc/dummy.version", new StringBuilder() - .AppendLine($"VERSION=${props.CloudWatchAgentConfigVersion}") - .ToString(), - new InitFileOptions() { Mode = "000400", Owner = "root", Group = "root"} + InitFile.FromString( + "/opt/aws/amazon-cloudwatch-agent/etc/dummy.version", + $"VERSION=${props.CloudWatchAgentConfigVersion}", + new InitFileOptions() { + Mode = "000400", + Owner = "root", + Group = "root" + } ) }) }, { "06_restart-amazon-cloudwatch-agent", new InitConfig(new InitElement[] { - InitCommand.ShellCommand("/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop"), - InitCommand.ShellCommand(Fn.Sub("/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssm} -s", new Dictionary(){ {"ssm", cwAgentConfigParameterName} })) - }) - }, - { - "07_xray-daemon-download", - new InitConfig(new InitElement[] { - //TODO: This was the original configuration, but has since stopped working, results in an S3 403 error - //InitFile.FromUrl("/tmp/xray.rpm", new StringBuilder() - // .AppendLine(Fn.Sub("https://s3.${AWS::Region}.amazonaws.com/aws-xray-assets.${AWS::Region}/xray-daemon/aws-xray-daemon${arch}-3.x.rpm", new Dictionary(){ { "arch", props.CpuArch == CpuArch.ARM_64 ? "-arm64" : "" } })) - // .ToString(), - // new InitFileOptions() { Mode = "000400", Owner = "root", Group = "root"} - //) - InitCommand.ShellCommand(Fn.Sub("curl https://s3.${AWS::Region}.${AWS::URLSuffix}/aws-xray-assets.${AWS::Region}/xray-daemon/aws-xray-daemon${arch}-3.x.rpm --output /tmp/xray.rpm", new Dictionary(){ { "arch", props.CpuArch == InstanceArchitecture.ARM_64 ? "-arm64" : "" } })) - }) - }, - { - "08_xray-daemon-install", - new InitConfig(new InitElement[] { - InitPackage.Rpm("/tmp/xray.rpm"), - InitCommand.ShellCommand("rm /tmp/xray.rpm") + InitCommand.ShellCommand("/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop"), + InitCommand.ShellCommand(Fn.Sub("/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ssm} -s", new Dictionary(){ {"ssm", cwAgentConfigParameterName} })), + InitCommand.ShellCommand("/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status") }) }, {