Complete the code to retrieve the instance ID from metadata.
curl http://169.254.169.254/latest/meta-data/[1]
The instance ID is accessed via the 'instance-id' path in the metadata service.
Complete the code to fetch the user data of an EC2 instance.
curl http://169.254.169.254/latest/[1]
User data is accessed via the 'user-data' path in the metadata service.
Fix the error in the command to get the public IPv4 address from metadata.
curl http://169.254.169.254/latest/meta-data/[1]
The public IPv4 address is accessed via the 'public-ipv4' path.
Fill both blanks to retrieve the security groups and the AMI ID from metadata.
curl http://169.254.169.254/latest/meta-data/[1] && curl http://169.254.169.254/latest/meta-data/[2]
'security-groups' returns the security groups attached to the instance, and 'ami-id' returns the AMI used to launch the instance.
Fill all three blanks to write a shell script that fetches instance ID, user data, and availability zone.
#!/bin/bash INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/[1]) USER_DATA=$(curl http://169.254.169.254/latest/[2]) AZ=$(curl http://169.254.169.254/latest/meta-data/[3]) echo "Instance ID: $INSTANCE_ID" echo "User Data: $USER_DATA" echo "Availability Zone: $AZ"
This script fetches the instance ID, user data, and availability zone from the metadata service using the correct paths.