DEV Community

Cover image for Why you should use IMDSv2 - How to get information about ec2 from ec2
Wojciech Lepczyński for AWS Community Builders

Posted on • Edited on

1

Why you should use IMDSv2 - How to get information about ec2 from ec2

The Instance Metadata Service (IMDS) allows EC2 instances to access metadata about themselves, such as instance ID, IP address, AMI ID and more.

IMDSv1 is the old way and is no longer recommended by AWS.

curl http://169.254.169.254/latest/meta-data/instance-id
Enter fullscreen mode Exit fullscreen mode

Using IMDSv2 on EC2 instances in AWS Cloud provides a more secure way to access instance metadata and is recommended by AWS. It offers built-in protections against common types of metadata service exploitation. Additionally, it allows for more granular control over access to instance metadata, which can help reduce the risk of unauthorized access.

TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`

curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id
Enter fullscreen mode Exit fullscreen mode

Overall, using IMDSv2 on EC2 instances in AWS Cloud can help improve the security of your applications and data, and is therefore worth considering if you are using EC2 instances in your infrastructure.

If you want to know more, learn about good practices and receive practical advice, I invite you to watch my video: https://youtu.be/91stm1cEIG4

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay