aws / amazon-ec2-metadata-mock

A tool to simulate Amazon EC2 instance metadata
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
Apache License 2.0
262 stars 44 forks source link

Dump all metadata to a file #174

Open bwagner5 opened 2 years ago

bwagner5 commented 2 years ago

Describe the feature A concise description of the feature and desired behavior.

AL2 dumps all the metadata to a file on the instance which is useful for looking at what's available globally or for quick access without having to use HTTP (or for when the metadata endpoint is restricted).

It would be useful to be able to generate this file with ec2-metadata-mock.

$ cat  /run/cloud-init/instance-data.json
{
 "base64_encoded_keys": [],
 "ds": {
  "_doc": "EXPERIMENTAL: The structure and format of content scoped under the 'ds' key may change in subsequent releases of cloud-init.",
  "_metadata_api_version": "2016-09-02",
  "dynamic": {
   "instance-identity": {
    "document": {
     "accountId": "xxxxxxxxxxxxxxxxx",
     "architecture": "x86_64",
     "availabilityZone": "us-west-2c",
     "billingProducts": null,
     "devpayProductCodes": null,
     "imageId": "ami-03af6523db112033e",
     "instanceId": "i-019f3238ddb9db5c1",
     "instanceType": "m5.4xlarge",
     "kernelId": null,
     "marketplaceProductCodes": null,
     "pendingTime": "2022-04-27T17:56:39Z",
     "privateIp": "192.168.8.35",
     "ramdiskId": null,
     "region": "us-west-2",
     "version": "2017-09-30"
    },
    "pkcs7": [
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ],
    "rsa2048": [
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ],
    "signature": [
     "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ]
   }
  },
  "meta-data": {
   "ami-id": "ami-03af6523db112033e",
   "ami-launch-index": "0",
   "ami-manifest-path": "(unknown)",
   "block-device-mapping": {
    "ami": "xvda",
    "root": "/dev/xvda"
   },
   "hostname": "ip-192-168-8-35.us-west-2.compute.internal",
   "iam": {
    "info": {
     "Code": "Success",
     "InstanceProfileArn": "arn:aws:iam::xxxxxxxxxxxx:instance-profile/xxxxxxxxxxxxxxxxx",
     "InstanceProfileId": "xxxxxxxxxxxxxxxxxxxxxxxx",
     "LastUpdated": "2022-04-27T17:56:40Z"
    }
   },
   "instance-action": "none",
   "instance-id": "i-019f3238ddb9db5c1",
   "instance-type": "m5.4xlarge",
   "local-hostname": "ip-192-168-8-35.us-west-2.compute.internal",
   "local-ipv4": "192.168.8.35",
   "mac": "xxxxxxxxxxxxxxxx",
   "metrics": {
    "vhostmd": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
   },
   "network": {
    "interfaces": {
     "macs": {
      "xxxxxxxxxxxxx": {
       "device-number": "0",
       "interface-id": "eni-xxxxxxxxxxxxxx",
       "ipv4-associations": {
        "xxxxxxxxxxxxxxx": "192.168.8.35"
       },
       "local-hostname": "ip-192-168-8-35.us-west-2.compute.internal",
       "local-ipv4s": "192.168.8.35",
       "mac": "xxxxxxxxxxxxx",
       "owner-id": "xxxxxxxxxxxxxx",
       "public-hostname": "ec2-xxxxxxxxx.us-west-2.compute.amazonaws.com",
       "public-ipv4s": "xxxxxxxxxxxxxxxxx",
       "security-group-ids": "xxxxxxxxxxxxxxxxxx",
       "security-groups": "xxxxxxxxxxxxxxxxxxxxxxxxx",
       "subnet-id": "subnet-0e1c2770e9430751e",
       "subnet-ipv4-cidr-block": "192.168.0.0/19",
       "vpc-id": "vpc-02e676af1f39c5f08",
       "vpc-ipv4-cidr-block": "192.168.0.0/16",
       "vpc-ipv4-cidr-blocks": "192.168.0.0/16"
      }
     }
    }
   },
   "placement": {
    "availability-zone": "us-west-2c"
   },
   "profile": "default-hvm",
   "public-hostname": "ec2-xxxxxxxxxxxxxxx.us-west-2.compute.amazonaws.com",
   "public-ipv4": "xxxxxxxxxxxx,
   "reservation-id": "r-067e0510e77dcf3d6",
   "security-groups": "xxxxxxxxxxxxxxxx",
   "services": {
    "domain": "amazonaws.com",
    "partition": "aws"
   }
  }
 },
 "sensitive_keys": [],
 "v1": {
  "_beta_keys": [
   "subplatform"
  ],
  "availability-zone": "us-west-2c",
  "availability_zone": "us-west-2c",
  "cloud-name": "aws",
  "cloud_name": "aws",
  "instance-id": "i-019f3238ddb9db5c1",
  "instance_id": "i-019f3238ddb9db5c1",
  "local-hostname": "ip-192-168-8-35",
  "local_hostname": "ip-192-168-8-35",
  "platform": "ec2",
  "public_ssh_keys": [],
  "region": "us-west-2",
  "subplatform": "metadata (http://169.254.169.254)"
 }
}

Is the feature request related to a problem? A description of what the problem is. For example: I'm frustrated when [...]

It may be desirable to rely on this file instead of using an HTTP client to receive metadata for various reasons. So making it easier to test with this file is useful.

Describe alternatives you've considered A description of any alternative solutions or features you've considered.

Could construct this manually, but it's a pain.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want this issue to never become stale, please ask a maintainer to apply the "stalebot-ignore" label.

bwagner5 commented 2 years ago

If all the data is available, cloud-init will dump it w/ this CLI command: https://cloudinit.readthedocs.io/en/latest/topics/cli.html#:~:text=dump%3A%20machine%2Dreadable%20JSON%20dump%20of%20all%20cloud%2Dinit%20tracked%20events

cloud-init analyze dump
github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want this issue to never become stale, please ask a maintainer to apply the "stalebot-ignore" label.