@Test
public void imdsv2() {

    stubFor(any(urlPathEqualTo("/latest/api/token")).willReturn(ok("token")));
    stubFor(any(urlPathEqualTo("/latest/dynamic/instance-identity/document"))
                .willReturn(okJson(IDENTITY_DOCUMENT)));
    Map<EC2MetadataFetcher.EC2Metadata, String> metadata = fetcher.fetch();
    assertThat(metadata).containsOnly(
        entry(EC2MetadataFetcher.EC2Metadata.INSTANCE_ID, "i-1234567890abcdef0"),
        entry(EC2MetadataFetcher.EC2Metadata.AVAILABILITY_ZONE, "us-west-2b"),
        entry(EC2MetadataFetcher.EC2Metadata.INSTANCE_TYPE, "t2.micro"),
        entry(EC2MetadataFetcher.EC2Metadata.AMI_ID, "ami-5fb8c835"));
    verify(putRequestedFor(urlEqualTo("/latest/api/token"))
               .withHeader("X-aws-ec2-metadata-token-ttl-seconds", equalTo("60")));
    verify(getRequestedFor(urlEqualTo("/latest/dynamic/instance-identity/document"))
               .withHeader("X-aws-ec2-metadata-token", equalTo("token")));
}