Attach IAM Roles and configure EC2 metadata

Now we will use the IAM Roles that we created earlier to assign to two EC2 instances.

Configure the Role and Set Up Metadata for DevEC2

Go to the EC2 management console and access the list of EC2 instances.

  • Select the EC2 instance you want to assign dev-ec2

2-image

  • Open the dropdown menu and choose the correct role we previously named DevEC2
  • Click Update IAM role to confirm.

2-image

Next, for this same EC2 instance, we will adjust the settings to retrieve metadata from the EC2 instance.

2-image

  • Instance metadata service: Enable (it’s usually enabled by default)
  • IMDSv2: change to Optional

2-image

Assign IAM Role for Prod EC2

Similarly, we will perform the same steps for the EC2 instance imga-server

  • Select imga-server

2-image

  • Open the dropdown menu and choose the correct role we previously named ProdEC2
  • Click Update IAM role to confirm.

2-image

Next, we will adjust the settings to retrieve metadata from the EC2 instance.

2-image

The remaining steps are exactly the same as for dev-ec2. At this point, we can ensure that both EC2 instances can communicate with each other and use the necessary services reliably.