@@ -94,14 +94,42 @@ echo "VPC ID: $vpc_id"
94
94
95
95
# ## Connecting to the Bastion Host
96
96
97
- To establish a connection with the bastion host, use the following commands:
97
+ To establish a secure connection with the bastion host, follow these steps:
98
+
99
+ # ### Obtain Required Information
100
+
101
+ First, you need to gather some essential information:
102
+
103
+ - Bastion SSH Parameter Name
104
+ - Bastion Instance ID
105
+
106
+ You can retrieve these values using Terraform:
98
107
99
108
` ` ` bash
100
- # Retrieve the SSH command from the Terraform output
101
- ssh_command=$( terraform output -json | jq -r ' .bastion_ssh_command.value' )
109
+ bastion_ssh_parameter_name=$( terraform output -json | jq -r ' .ssm_parameter_bastion_ssh_key.value' )
110
+ bastion_instance_id=$( terraform output -json | jq -r ' .bastion_instance_id.value' )
111
+ ` ` `
112
+
113
+ # ### Generate .pem file with the ssh key
114
+
115
+ ` ` ` bash
116
+ aws ssm get-parameter --name " $bastion_ssh_parameter_name " --with-decryption --query ' Parameter.Value' --output text > /tmp/ssh_key.pem
117
+ chmod 400 /tmp/ssh_key.pem
118
+ ` ` `
102
119
103
- # Execute the SSH command
104
- eval $ssh_command
120
+ # ### Retrieve bastion's public IP
121
+
122
+ ` ` ` bash
123
+ bastion_public_ip=$( aws ec2 describe-instances --instance-ids " $bastion_instance_id " --query ' Reservations[0].Instances[0].PublicIpAddress' --output text | tr ' .' ' -' )
124
+
125
+ # Print the value
126
+ echo " Bastion IP: $bastion_public_ip "
127
+ ` ` `
128
+
129
+ # ### Connect to Bastion Host
130
+
131
+ ` ` ` bash
132
+ ssh -i " /tmp/ssh_key.pem" ubuntu@ec2-" $bastion_public_ip " .us-west-2.compute.amazonaws.com
105
133
` ` `
106
134
107
135
Ensure that you can access the database from the bastion host and verify that Docker is functioning correctly.
0 commit comments