-
Notifications
You must be signed in to change notification settings - Fork 21
Add the SSMManagedInstanceCore policy to all EC2 resources #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8ee56a7
0d10792
9de6faa
59d154f
ac6077d
4bc4a65
7ee0518
8137726
286765c
faa26f8
706844a
45cb5b0
5d9261f
992d488
c2ad554
2ebaef2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,9 @@ Parameters: | |||||||||||||||||||||||||||||||||||||
| KeyPair: | ||||||||||||||||||||||||||||||||||||||
| Type: "AWS::EC2::KeyPair::KeyName" | ||||||||||||||||||||||||||||||||||||||
| Description: Name of an existing EC2 KeyPair to enable SSH access to the instance. If no key pairs exist, please create one from the button next to the dropdown. Please contact your Administrator if you are unable to create one. | ||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: | ||||||||||||||||||||||||||||||||||||||
| Description: Select the availability zone in which to create the instance. If you plan to attach a secondary volume to the instance, create this instance in the same AvailabilityZone as the volume you created. | ||||||||||||||||||||||||||||||||||||||
| Type: AWS::EC2::AvailabilityZone::Name | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Conditions: | ||||||||||||||||||||||||||||||||||||||
| IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}'] | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +59,8 @@ Resources: | |||||||||||||||||||||||||||||||||||||
| - 'ec2.amazonaws.com' | ||||||||||||||||||||||||||||||||||||||
| Action: | ||||||||||||||||||||||||||||||||||||||
| - 'sts:AssumeRole' | ||||||||||||||||||||||||||||||||||||||
| ManagedPolicyArns: | ||||||||||||||||||||||||||||||||||||||
| - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore | ||||||||||||||||||||||||||||||||||||||
| Policies: | ||||||||||||||||||||||||||||||||||||||
| - !If | ||||||||||||||||||||||||||||||||||||||
| - IamPolicyEmpty | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,7 +125,16 @@ Resources: | |||||||||||||||||||||||||||||||||||||
| group: 'root' | ||||||||||||||||||||||||||||||||||||||
| content: !Sub | | ||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||
| instance_id=$(curl -s "http://169.254.169.254/latest/meta-data/instance-id") | ||||||||||||||||||||||||||||||||||||||
| # Get the session token | ||||||||||||||||||||||||||||||||||||||
| TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Get the region to build the parameter name | ||||||||||||||||||||||||||||||||||||||
| instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region) | ||||||||||||||||||||||||||||||||||||||
| echo "Retrieved region ${region} from metadata service" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Get the instance id to build the parameter name | ||||||||||||||||||||||||||||||||||||||
| instance_id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+128
to
+137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Undefined variable in debug echo
-echo "Retrieved region ${region} from metadata service"
+echo "Retrieved region ${instance_region} from metadata service"📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 130-130: trailing spaces (trailing-spaces) [error] 134-134: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| secret=`uuidgen` | ||||||||||||||||||||||||||||||||||||||
| echo "setting ${InitialUser} password and starting rstudio" | ||||||||||||||||||||||||||||||||||||||
| password=$(echo -n "$instance_id$secret" | sha256sum | awk '{print $1}') | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -129,7 +143,7 @@ Resources: | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| sleep 10 | ||||||||||||||||||||||||||||||||||||||
| public_key=$(curl http://localhost:8787/auth-public-key) | ||||||||||||||||||||||||||||||||||||||
| instance_region=$(curl -s "http://169.254.169.254/latest/meta-data/placement/region") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| aws ssm put-parameter --name "/RL/RG/rstudio/public-key/$instance_id" --value '{"secret":"'$secret'","public_key":"'$public_key'"}' --region $instance_region --type SecureString --overwrite | ||||||||||||||||||||||||||||||||||||||
| echo "Stored rstudio public key in SSM" | ||||||||||||||||||||||||||||||||||||||
| '/var/log/rstudio.log': | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -150,6 +164,7 @@ Resources: | |||||||||||||||||||||||||||||||||||||
| Properties: | ||||||||||||||||||||||||||||||||||||||
| ImageId : '{{resolve:ssm:/RL/RG/StandardCatalog/RStudio}}' | ||||||||||||||||||||||||||||||||||||||
| InstanceType: !Ref 'InstanceType' | ||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: !Ref AvailabilityZone | ||||||||||||||||||||||||||||||||||||||
| SecurityGroups: [!Ref 'RstudioEC2SecurityGroup'] | ||||||||||||||||||||||||||||||||||||||
| KeyName: !Ref 'KeyPair' | ||||||||||||||||||||||||||||||||||||||
| IamInstanceProfile: !Ref InstanceProfile | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -206,4 +221,4 @@ Outputs: | |||||||||||||||||||||||||||||||||||||
| Value: '443' | ||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: | ||||||||||||||||||||||||||||||||||||||
| Description: AvailabilityZone of newly created Rstudio EC2Instance | ||||||||||||||||||||||||||||||||||||||
| Value: !GetAtt [RstudioEC2Instance, AvailabilityZone] | ||||||||||||||||||||||||||||||||||||||
| Value: !Ref AvailabilityZone | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,9 @@ Parameters: | |||||||||||||||||||||||||||||||||||||||||
| KeyPair: | ||||||||||||||||||||||||||||||||||||||||||
| Type: "AWS::EC2::KeyPair::KeyName" | ||||||||||||||||||||||||||||||||||||||||||
| Description: Name of an existing EC2 KeyPair to enable SSH access to the instance. If no key pairs exist, please create one from the button next to the dropdown. Please contact your Administrator if you are unable to create one. | ||||||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: | ||||||||||||||||||||||||||||||||||||||||||
| Description: Select the availability zone in which to create the instance. If you plan to attach a secondary volume to the instance, create this instance in the same AvailabilityZone as the volume you created. | ||||||||||||||||||||||||||||||||||||||||||
| Type: AWS::EC2::AvailabilityZone::Name | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Conditions: | ||||||||||||||||||||||||||||||||||||||||||
| IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}'] | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +59,8 @@ Resources: | |||||||||||||||||||||||||||||||||||||||||
| - 'ec2.amazonaws.com' | ||||||||||||||||||||||||||||||||||||||||||
| Action: | ||||||||||||||||||||||||||||||||||||||||||
| - 'sts:AssumeRole' | ||||||||||||||||||||||||||||||||||||||||||
| ManagedPolicyArns: | ||||||||||||||||||||||||||||||||||||||||||
| - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore | ||||||||||||||||||||||||||||||||||||||||||
| Policies: | ||||||||||||||||||||||||||||||||||||||||||
| - !If | ||||||||||||||||||||||||||||||||||||||||||
| - IamPolicyEmpty | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -160,8 +165,17 @@ Resources: | |||||||||||||||||||||||||||||||||||||||||
| echo "fetching token and starting jupyterlab" | ||||||||||||||||||||||||||||||||||||||||||
| `docker-compose up -d` | ||||||||||||||||||||||||||||||||||||||||||
| sleep 5 | ||||||||||||||||||||||||||||||||||||||||||
| instance_id=$(curl -s "http://169.254.169.254/latest/meta-data/instance-id") | ||||||||||||||||||||||||||||||||||||||||||
| instance_region=$(curl -s "http://169.254.169.254/latest/meta-data/placement/region") | ||||||||||||||||||||||||||||||||||||||||||
| # Get the session token | ||||||||||||||||||||||||||||||||||||||||||
| TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Get the region to build the parameter name | ||||||||||||||||||||||||||||||||||||||||||
| instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region) | ||||||||||||||||||||||||||||||||||||||||||
| echo "Retrieved region ${region} from metadata service" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Get the instance id to build the parameter name | ||||||||||||||||||||||||||||||||||||||||||
| instance_id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id) | ||||||||||||||||||||||||||||||||||||||||||
| echo "Retrieved instance_id $instance_id from metadata service" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+168
to
+178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Variable typo drops useful debug output.
-echo "Retrieved region ${region} from metadata service"
+echo "Retrieved region ${instance_region} from metadata service"📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 170-170: trailing spaces (trailing-spaces) [error] 174-174: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| #access_token=$((docker exec jupyterlab /bin/bash -c "jupyter server list" | grep token | awk '{print $1}') | sed 's/.*=//') | ||||||||||||||||||||||||||||||||||||||||||
| #echo "$access_token" | ||||||||||||||||||||||||||||||||||||||||||
| docker exec jupyterlab /bin/bash -c "jupyter server list" > access_token.txt 2>&1 | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -198,6 +212,7 @@ Resources: | |||||||||||||||||||||||||||||||||||||||||
| KeyName: !Ref 'KeyPair' | ||||||||||||||||||||||||||||||||||||||||||
| IamInstanceProfile: !Ref InstanceProfile | ||||||||||||||||||||||||||||||||||||||||||
| PropagateTagsToVolumeOnCreation: true | ||||||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: !Ref AvailabilityZone | ||||||||||||||||||||||||||||||||||||||||||
| BlockDeviceMappings: | ||||||||||||||||||||||||||||||||||||||||||
| - DeviceName: /dev/xvda | ||||||||||||||||||||||||||||||||||||||||||
| Ebs: | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -269,4 +284,4 @@ Outputs: | |||||||||||||||||||||||||||||||||||||||||
| Value: '443' | ||||||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: | ||||||||||||||||||||||||||||||||||||||||||
| Description: AvailabilityZone of newly created JupyterLab EC2Instance | ||||||||||||||||||||||||||||||||||||||||||
| Value: !GetAtt [EC2Instance, AvailabilityZone] | ||||||||||||||||||||||||||||||||||||||||||
| Value: !Ref AvailabilityZone | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,9 +59,20 @@ Resources: | |||||||||||||
| PolicyDocument: | ||||||||||||||
| Version: "2012-10-17" | ||||||||||||||
| Statement: | ||||||||||||||
| - Effect: Allow | ||||||||||||||
| - Sid: AllowSSMParamActions | ||||||||||||||
| Effect: Allow | ||||||||||||||
| Action: | ||||||||||||||
| - ssm:GetParameter | ||||||||||||||
| - ssm:PutParameter | ||||||||||||||
| - ssm:DescribeParameters | ||||||||||||||
| Resource: "*" | ||||||||||||||
| - Sid: AllowAccessToEncryptionKeys | ||||||||||||||
| Effect: Allow | ||||||||||||||
| Action: | ||||||||||||||
| - ssm:* | ||||||||||||||
| - kms:Decrypt | ||||||||||||||
| - kms:Encrypt | ||||||||||||||
| - kms:GenerateDataKey | ||||||||||||||
| - kms:DescribeKey | ||||||||||||||
| Resource: "*" | ||||||||||||||
| InstanceRolePermissionBoundary: | ||||||||||||||
| Type: AWS::IAM::ManagedPolicy | ||||||||||||||
|
|
@@ -300,9 +311,18 @@ Resources: | |||||||||||||
| group: "ec2-user" | ||||||||||||||
| content: !Sub | | ||||||||||||||
| #!/bin/bash | ||||||||||||||
| # trap '/opt/aws/bin/cfn-signal --exit-code 1 --resource EC2Instance --region ${AWS::Region} --stack ${AWS::StackName}' ERR | ||||||||||||||
| region=$(curl -s "http://169.254.169.254/latest/meta-data/placement/region") | ||||||||||||||
| instance_id=$(curl -s "http://169.254.169.254/latest/meta-data/instance-id") | ||||||||||||||
| trap "Error setting user token. You may not be able to access your instance URL" ERR | ||||||||||||||
| # Get the session token | ||||||||||||||
| TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | ||||||||||||||
|
|
||||||||||||||
| # Get the region to build the parameter name | ||||||||||||||
| region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region) | ||||||||||||||
| echo "Retrieved region ${region} from metadata service" | ||||||||||||||
|
|
||||||||||||||
| # Get the instance id to build the parameter name | ||||||||||||||
| instance_id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id) | ||||||||||||||
| echo "Retrieved instance_id $instance_id from metadata service" | ||||||||||||||
|
|
||||||||||||||
| session_id="rg-session" | ||||||||||||||
| auth_token=`uuidgen` | ||||||||||||||
| parameter_name="/RL/RG/secure-desktop/auth-token/$instance_id" | ||||||||||||||
|
|
@@ -382,6 +402,9 @@ Resources: | |||||||||||||
| cwd: "/home/ec2-user" | ||||||||||||||
| command: "/home/ec2-user/start_jupyter.sh" | ||||||||||||||
| Properties: | ||||||||||||||
| LaunchTemplate: | ||||||||||||||
| LaunchTemplateName: "RG-IMDSv2" | ||||||||||||||
| Version: 1 | ||||||||||||||
|
Comment on lines
+405
to
+407
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
YAML interprets bare - Version: 1
+ Version: "1"📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 407-407: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents |
||||||||||||||
| UserData: | ||||||||||||||
| Fn::Base64: !Sub | | ||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||
|
|
@@ -454,7 +477,7 @@ Resources: | |||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| BlockDeviceMappings: | ||||||||||||||
| - DeviceName: /dev/xvda | ||||||||||||||
| - DeviceName: /dev/sda1 | ||||||||||||||
| Ebs: | ||||||||||||||
| VolumeSize: !Ref EBSVolumeSize | ||||||||||||||
| Encrypted: true | ||||||||||||||
|
|
@@ -469,11 +492,13 @@ Resources: | |||||||||||||
| PropagateTagsToVolumeOnCreation: true | ||||||||||||||
| Tags: | ||||||||||||||
| - Key: Name | ||||||||||||||
| Value: !Join ["-", [Ref: Namespace, "ec2-linux"]] | ||||||||||||||
| Value: !Join ["-", [Ref: Namespace, "ec2-secure-linux"]] | ||||||||||||||
| - Key: Description | ||||||||||||||
| Value: EC2 workspace instance | ||||||||||||||
| - Key: cost_resource | ||||||||||||||
| Value: !Sub ${AWS::StackName} | ||||||||||||||
| - Key: PatchGroup | ||||||||||||||
| Value: RG-PatchGroup-Linux | ||||||||||||||
|
|
||||||||||||||
| InstanceSecurityGroup: | ||||||||||||||
| Type: AWS::EC2::SecurityGroup | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,10 @@ Parameters: | |||||||||||||||||||||||||||||||||||||||||||||
| EBSVolumeSize: | ||||||||||||||||||||||||||||||||||||||||||||||
| Description: The initial size of the volume (in GBs), Select volume size must be 32 or above. | ||||||||||||||||||||||||||||||||||||||||||||||
| Type: Number | ||||||||||||||||||||||||||||||||||||||||||||||
| Default: 32 | ||||||||||||||||||||||||||||||||||||||||||||||
| Default: 32 | ||||||||||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: | ||||||||||||||||||||||||||||||||||||||||||||||
| Description: Select the availability zone in which to create the instance. If you plan to attach a secondary volume to the instance, create this instance in the same AvailabilityZone as the volume you created. | ||||||||||||||||||||||||||||||||||||||||||||||
| Type: AWS::EC2::AvailabilityZone::Name | ||||||||||||||||||||||||||||||||||||||||||||||
| InstanceType: | ||||||||||||||||||||||||||||||||||||||||||||||
| Type: String | ||||||||||||||||||||||||||||||||||||||||||||||
| Description: Choose the instance type e.g t3.medium (2vCPU , 2GiB RAM), t3.large (2vCPU, 8GiB RAM), t3.xlarge(4vCPU, 16GiB RAM) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -56,6 +59,8 @@ Resources: | |||||||||||||||||||||||||||||||||||||||||||||
| - 'ec2.amazonaws.com' | ||||||||||||||||||||||||||||||||||||||||||||||
| Action: | ||||||||||||||||||||||||||||||||||||||||||||||
| - 'sts:AssumeRole' | ||||||||||||||||||||||||||||||||||||||||||||||
| ManagedPolicyArns: | ||||||||||||||||||||||||||||||||||||||||||||||
| - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore | ||||||||||||||||||||||||||||||||||||||||||||||
| Policies: | ||||||||||||||||||||||||||||||||||||||||||||||
| - !If | ||||||||||||||||||||||||||||||||||||||||||||||
| - IamPolicyEmpty | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -163,8 +168,16 @@ Resources: | |||||||||||||||||||||||||||||||||||||||||||||
| access_token=`uuidgen` | ||||||||||||||||||||||||||||||||||||||||||||||
| `PASSWORD=$access_token docker-compose up -d` | ||||||||||||||||||||||||||||||||||||||||||||||
| sleep 5 | ||||||||||||||||||||||||||||||||||||||||||||||
| instance_id=$(curl -s "http://169.254.169.254/latest/meta-data/instance-id") | ||||||||||||||||||||||||||||||||||||||||||||||
| instance_region=$(curl -s "http://169.254.169.254/latest/meta-data/placement/region") | ||||||||||||||||||||||||||||||||||||||||||||||
| # Get the session token | ||||||||||||||||||||||||||||||||||||||||||||||
| TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Get the region to build the parameter name | ||||||||||||||||||||||||||||||||||||||||||||||
| instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region) | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "Retrieved region ${region} from metadata service" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Get the instance id to build the parameter name | ||||||||||||||||||||||||||||||||||||||||||||||
| instance_id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id) | ||||||||||||||||||||||||||||||||||||||||||||||
| echo "Retrieved instance_id $instance_id from metadata service" | ||||||||||||||||||||||||||||||||||||||||||||||
| aws ssm put-parameter --name "/RL/RG/vs-code/auth-token/$instance_id" --value $access_token --region $instance_region --type SecureString --overwrite | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+171
to
181
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix variable‐name typo & quote the token before logging
- instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
- echo "Retrieved region ${region} from metadata service"
+instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
+echo "Retrieved region ${instance_region} from metadata service"
- aws ssm put-parameter --name "/RL/RG/vs-code/auth-token/$instance_id" --value $access_token --region $instance_region --type SecureString --overwrite
+aws ssm put-parameter --name "/RL/RG/vs-code/auth-token/$instance_id" --value "$access_token" --region "$instance_region" --type SecureString --overwrite 📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[error] 173-173: trailing spaces (trailing-spaces) [error] 177-177: trailing spaces (trailing-spaces) [error] 181-181: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| echo "Stored vscode token in SSM" | ||||||||||||||||||||||||||||||||||||||||||||||
| '/var/log/vscode.log': | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -185,6 +198,7 @@ Resources: | |||||||||||||||||||||||||||||||||||||||||||||
| Properties: | ||||||||||||||||||||||||||||||||||||||||||||||
| ImageId : '{{resolve:ssm:/RL/RG/StandardCatalog/VS-Code}}' | ||||||||||||||||||||||||||||||||||||||||||||||
| InstanceType: !Ref 'InstanceType' | ||||||||||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: !Ref AvailabilityZone | ||||||||||||||||||||||||||||||||||||||||||||||
| BlockDeviceMappings: | ||||||||||||||||||||||||||||||||||||||||||||||
| - DeviceName: /dev/xvda | ||||||||||||||||||||||||||||||||||||||||||||||
| Ebs: | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -267,4 +281,4 @@ Outputs: | |||||||||||||||||||||||||||||||||||||||||||||
| Value: '443' | ||||||||||||||||||||||||||||||||||||||||||||||
| AvailabilityZone: | ||||||||||||||||||||||||||||||||||||||||||||||
| Description: AvailabilityZone of newly created VS-Code EC2Instance | ||||||||||||||||||||||||||||||||||||||||||||||
| Value: !GetAtt [EC2Instance, AvailabilityZone] | ||||||||||||||||||||||||||||||||||||||||||||||
| Value: !Ref AvailabilityZone | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Trailing spaces + missing error handling for empty IMDS token
YAMLlintflags trailing whitespace on 318 & 322.Also, if the PUT fails (e.g. IMDSv1 disabled but v2 not yet enabled),
$TOKENis empty and the subsequent calls succeed unauthenticated, defeating the purpose.📝 Committable suggestion
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 318-318: trailing spaces
(trailing-spaces)
[error] 322-322: trailing spaces
(trailing-spaces)
🤖 Prompt for AI Agents