Retrieve the AWS Marketplace product code from your instance - Amazon Elastic Compute Cloud

Retrieve the AWS Marketplace product code from your instance

You can retrieve the AWS Marketplace product code for your instance using its instance metadata. If the instance has a product code, Amazon EC2 returns it. For more information about retrieving metadata, see Access instance metadata for an EC2 instance.

To retrieve a product code, use the command for your instance's operating system.

IMDSv2
[ec2-user ~]$ 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" http://169.254.169.254/latest/meta-data/product-codes
IMDSv1
[ec2-user ~]$ curl http://169.254.169.254/latest/meta-data/product-codes
PS C:\> Invoke-RestMethod -uri http://169.254.169.254/latest/meta-data/product-codes