Skip to content

Commit

Permalink
removing ec2 again
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Haken committed Feb 13, 2025
1 parent 141e212 commit 33da28e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 deletions.
13 changes: 9 additions & 4 deletions cdk/Configs/cw-agent-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
}
2 changes: 1 addition & 1 deletion cdk/MultiAZWorkshopStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
44 changes: 15 additions & 29 deletions cdk/NestedStacks/EC2FleetStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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<string, string>(){ { "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<string, string>(){ { "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<string, string>(){ {"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<string, string>(){ { "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<string, string>(){ { "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<string, string>(){ {"ssm", cwAgentConfigParameterName} })),
InitCommand.ShellCommand("/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status")
})
},
{
Expand Down

0 comments on commit 33da28e

Please sign in to comment.