Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29449

How to access EC2 instance metadata service? From outside EC2

$
0
0

With the below configuration for AWS cloud watch:

awslogs.conf

[/var/log/messages]
datetime_format = %b %d %H:%M:%S
file = /var/log/messages
buffer_duration = 2500
log_group_name = /var/log/messages
log_stream_name = {cluster}{instance_id}

and below script used with --userdata option for aws ec2 command:

userdata.sh

# Above agentlogs.conf file is copied to /etc/awslogs/awslogs.conf in AWS EC2 instance


# Configure cloudwatch  config file
cat > /etc/cloudwatch-logs.ini <<EOF
[/var/log/messages]
datetime_format = %b %d %H:%M:%S
file = /var/log/messages
buffer_duration = 2500
log_stream_name = {cluster}{instance_id}
initial_position = start_of_file
log_group_name = /var/log/messages
EOF

an EC2 is launched from this script(running outside EC2):

spin_up_ec2.sh

# Using AWS CLI,  we spin up EC2 instance using userdata.sh, 
# Using metadata service How to read values of {cluster} & {instance_id} syntax, shown above:

aws logs describe-log-streams --log-group-name /var/log/messages --log-stream-name-prefix <grab_cluster_name_value><grab_instance_id_value> --region us-east-1

spin_up_ec2.sh is sitting outside EC2, within same VPC, in different subnet. So, am not sure, how to avail EC2 metadata service?

EC2 is running in private subnet.

{cluster} value would be something like clust1

{instance_id} value would be something like i-1a52627268bc


1)

How can a shell script(spin_up_ec2.sh) client talk to EC2 metadata service, to retrieve values of {cluster}& {instance_id}?

2)

Does launching EC2 in public subnet, help? To talk to metadata service


Viewing all articles
Browse latest Browse all 29449

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>