@@ -733,12 +733,6 @@ Resources:
733733 Fn::GetAtt :
734734 - IdeInstanceLauncherFunction803C5A2A
735735 - Arn
736- InstanceName : ide
737- IamInstanceProfileArn :
738- Fn::GetAtt :
739- - IdeIdeInstanceProfile8BD997EA
740- - Arn
741- VolumeSize : " 50"
742736 SubnetIds :
743737 Fn::Join :
744738 - " "
@@ -758,126 +752,114 @@ Resources:
758752 ImageId :
759753 Ref : SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter
760754 UserData :
761- Fn::Base64 :
762- Fn::Join :
763- - " "
764- - - |
765- # !/bin/bash
766- - Fn::Sub :
767- - |-
768- #!/bin/bash
769- set -e
755+ Fn::Base64 : |-
756+ # !/bin/bash
757+ # !/bin/bash
758+ set -e
770759
771- # Minimal EC2 UserData script - downloads and runs full bootstrap
772- # This keeps UserData under size limits while allowing unlimited bootstrap size
760+ # Minimal EC2 UserData script - downloads and runs full bootstrap
761+ # This keeps UserData under size limits while allowing unlimited bootstrap size
773762
774- # Configuration from CDK
775- GIT_BRANCH="${gitBranch:-main}"
776- IDE_PASSWORD="${idePassword}"
777- STACK_NAME="${stackName}"
778- AWS_REGION="${awsRegion}"
779- TEMPLATE_TYPE="${templateType:-base}"
780- VSCODE_EXTENSIONS="${vscodeExtensions:-}"
763+ # Configuration from CDK
764+ GIT_BRANCH="${gitBranch:-main}"
765+ IDE_PASSWORD="${idePassword}"
766+ STACK_NAME="${stackName}"
767+ AWS_REGION="${awsRegion}"
768+ TEMPLATE_TYPE="${templateType:-base}"
769+ VSCODE_EXTENSIONS="${vscodeExtensions:-}"
781770
782- # Setup logging
783- LOG_GROUP_NAME="ide-bootstrap-$(date +%Y%m%d-%H%M%S)"
784- echo "Bootstrap logs will be written to CloudWatch log group: $LOG_GROUP_NAME"
771+ # Setup logging
772+ LOG_GROUP_NAME="ide-bootstrap-$(date +%Y%m%d-%H%M%S)"
773+ echo "Bootstrap logs will be written to CloudWatch log group : $LOG_GROUP_NAME"
785774
786- # Install CloudWatch agent for logging
787- dnf install -y amazon-cloudwatch-agent
775+ # Install CloudWatch agent for logging
776+ dnf install -y amazon-cloudwatch-agent
788777
789- # Create CloudWatch agent configuration
790- cat > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json << EOF
778+ # Create CloudWatch agent configuration
779+ cat > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json << EOF
780+ {
781+ " logs " : {
782+ " logs_collected " : {
783+ " files " : {
784+ " collect_list " : [
791785 {
792- "logs": {
793- "logs_collected": {
794- "files": {
795- "collect_list": [
796- {
797- "file_path": "/var/log/bootstrap.log",
798- "log_group_name": "$LOG_GROUP_NAME",
799- "log_stream_name": "{instance_id}",
800- "retention_in_days": 7
801- }
802- ]
803- }
804- }
805- }
786+ " file_path " : " /var/log/bootstrap.log" ,
787+ " log_group_name " : " $LOG_GROUP_NAME" ,
788+ " log_stream_name " : " {instance_id}" ,
789+ " retention_in_days " : 7
806790 }
807- EOF
791+ ]
792+ }
793+ }
794+ }
795+ }
796+ EOF
808797
809- # Start CloudWatch agent
810- /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
811- -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
798+ # Start CloudWatch agent
799+ /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
800+ -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
812801
813- # Redirect all output to log file and console
814- exec > >(tee -a /var/log/bootstrap.log)
815- exec 2>&1
802+ # Redirect all output to log file and console
803+ exec > >(tee -a /var/log/bootstrap.log)
804+ exec 2>&1
816805
817- echo "UserData started at $(date) - Logging to $LOG_GROUP_NAME"
806+ echo "UserData started at $(date) - Logging to $LOG_GROUP_NAME"
818807
819- # Download and run full bootstrap script with retry logic
820- download_bootstrap() {
821- local urls=(
822- "https://raw.githubusercontent.com/aws-samples/java-on-aws/${GIT_BRANCH}/infra/scripts/ide/bootstrap.sh"
823- "https://github.com/aws-samples/java-on-aws/raw/${GIT_BRANCH}/infra/scripts/ide/bootstrap.sh"
824- )
825- local max_attempts=5
826- local delay=5
808+ # Download and run full bootstrap script with retry logic
809+ download_bootstrap() {
810+ local urls=(
811+ " https://raw.githubusercontent.com/aws-samples/java-on-aws/${GIT_BRANCH}/infra/scripts/ide/bootstrap.sh"
812+ " https://github.com/aws-samples/java-on-aws/raw/${GIT_BRANCH}/infra/scripts/ide/bootstrap.sh"
813+ )
814+ local max_attempts=5
815+ local delay=5
827816
828- for attempt in $(seq 1 $max_attempts); do
829- echo "Download attempt $attempt of $max_attempts"
817+ for attempt in $(seq 1 $max_attempts); do
818+ echo "Download attempt $attempt of $max_attempts"
830819
831- for url in "${urls[@]}"; do
832- echo "Trying to download bootstrap from: $url"
833- if curl -fsSL --connect-timeout 30 --max-time 60 "$url" -o /tmp/bootstrap.sh; then
834- echo "Successfully downloaded bootstrap script on attempt $attempt"
835- return 0
836- fi
837- echo "Failed to download from: $url"
838- done
820+ for url in "${urls[@]}"; do
821+ echo "Trying to download bootstrap from : $url"
822+ if curl -fsSL --connect-timeout 30 --max-time 60 "$url" -o /tmp/bootstrap.sh; then
823+ echo "Successfully downloaded bootstrap script on attempt $attempt"
824+ return 0
825+ fi
826+ echo "Failed to download from : $url"
827+ done
839828
840- if [ $attempt -lt $max_attempts ]; then
841- echo "All URLs failed on attempt $attempt, waiting ${delay}s before retry..."
842- sleep $delay
843- fi
844- done
829+ if [ $attempt -lt $max_attempts ]; then
830+ echo "All URLs failed on attempt $attempt, waiting ${delay}s before retry..."
831+ sleep $delay
832+ fi
833+ done
845834
846- echo "All download attempts failed after $max_attempts tries"
847- return 1
848- }
835+ echo "All download attempts failed after $max_attempts tries"
836+ return 1
837+ }
849838
850- if download_bootstrap; then
851- chmod +x /tmp/bootstrap.sh
852- echo "Executing full bootstrap script..."
853- export VSCODE_EXTENSIONS="$VSCODE_EXTENSIONS"
854- if /tmp/bootstrap.sh "$IDE_PASSWORD" "$GIT_BRANCH" "$STACK_NAME" "$AWS_REGION" "$TEMPLATE_TYPE"; then
855- echo "Bootstrap completed successfully"
856- /opt/aws/bin/cfn-signal -e 0 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
857- else
858- echo "FATAL: Bootstrap script failed"
859- /opt/aws/bin/cfn-signal -e 1 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
860- exit 1
861- fi
862- else
863- echo "FATAL: Could not download bootstrap script from any source"
864- /opt/aws/bin/cfn-signal -e 1 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
865- exit 1
866- fi
867- - awsRegion :
868- Ref : AWS::Region
869- stackName :
870- Ref : AWS::StackName
871- gitBranch : new-ws-infra
872- vscodeExtensions : shardulm94.trailing-spaces,ms-kubernetes-tools.vscode-kubernetes-tools,ms-azuretools.vscode-docker
873- idePassword :
874- Fn::Join :
875- - " "
876- - - "{{resolve:secretsmanager:"
877- - Ref : IdeIdePasswordSecretF3482811
878- - :SecretString:password::}}
879- templateType : base
839+ if download_bootstrap; then
840+ chmod +x /tmp/bootstrap.sh
841+ echo "Executing full bootstrap script..."
842+ export VSCODE_EXTENSIONS="$VSCODE_EXTENSIONS"
843+ if /tmp/bootstrap.sh "$IDE_PASSWORD" "$GIT_BRANCH" "$STACK_NAME" "$AWS_REGION" "$TEMPLATE_TYPE"; then
844+ echo "Bootstrap completed successfully"
845+ /opt/aws/bin/cfn-signal -e 0 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
846+ else
847+ echo "FATAL : Bootstrap script failed"
848+ /opt/aws/bin/cfn-signal -e 1 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
849+ exit 1
850+ fi
851+ else
852+ echo "FATAL : Could not download bootstrap script from any source"
853+ /opt/aws/bin/cfn-signal -e 1 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
854+ exit 1
855+ fi
880856 InstanceTypes : m5.xlarge,m6i.xlarge,t3.xlarge
857+ InstanceName : ide
858+ IamInstanceProfileArn :
859+ Fn::GetAtt :
860+ - IdeIdeInstanceProfile8BD997EA
861+ - Arn
862+ VolumeSize : " 50"
881863 UpdateReplacePolicy : Delete
882864 DeletionPolicy : Delete
883865 IdeIdeEipAssociation6C6C215D :
@@ -1126,12 +1108,12 @@ Resources:
11261108 Environment :
11271109 ComputeType : BUILD_GENERAL1_MEDIUM
11281110 EnvironmentVariables :
1129- - Name : TEMPLATE_TYPE
1130- Type : PLAINTEXT
1131- Value : base
11321111 - Name : GIT_BRANCH
11331112 Type : PLAINTEXT
11341113 Value : new-ws-infra
1114+ - Name : TEMPLATE_TYPE
1115+ Type : PLAINTEXT
1116+ Value : base
11351117 - Name : STACK_NAME
11361118 Type : PLAINTEXT
11371119 Value :
@@ -1364,12 +1346,12 @@ Resources:
13641346 Description : base-setup build complete
13651347 EventPattern :
13661348 detail :
1367- project-name :
1368- - Ref : CodeBuildProjectA0FF5539
13691349 build-status :
13701350 - SUCCEEDED
13711351 - FAILED
13721352 - STOPPED
1353+ project-name :
1354+ - Ref : CodeBuildProjectA0FF5539
13731355 detail-type :
13741356 - CodeBuild Build State Change
13751357 source :
@@ -1401,13 +1383,13 @@ Resources:
14011383 Fn::GetAtt :
14021384 - CodeBuildStartLambdaFunction8349284F
14031385 - Arn
1404- ProjectName :
1405- Ref : CodeBuildProjectA0FF5539
14061386 CodeBuildIamRoleArn :
14071387 Fn::GetAtt :
14081388 - CodeBuildCodeBuildRoleBA9C6D5C
14091389 - Arn
1410- ContentHash : " 1765650683812"
1390+ ContentHash : " 1765651009800"
1391+ ProjectName :
1392+ Ref : CodeBuildProjectA0FF5539
14111393 DependsOn :
14121394 - CodeBuildBuildCompleteRuleAllowEventRuleWorkshopStackCodeBuildReportLambdaFunctionD77C6091DA4A4BD8
14131395 - CodeBuildBuildCompleteRule06AAF17D
0 commit comments