Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contradictory documentation on usage of ec2/imds GetMetadata #1173

Closed
saj opened this issue Mar 15, 2021 · 3 comments · Fixed by #2781
Closed

Contradictory documentation on usage of ec2/imds GetMetadata #1173

saj opened this issue Mar 15, 2021 · 3 comments · Fixed by #2781
Labels
bug This issue is a bug. documentation This is a problem with documentation. p3 This is a minor priority issue queued This issues is on the AWS team's backlog s Effort estimation: small

Comments

@saj
Copy link

saj commented Mar 15, 2021

https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected]#Client.GetMetadata

The content will be returned as a string

The function returns a value of type *GetMetadataOutput. There is no field of string type to be found in GetMetadataOutput.

https://aws.github.io/aws-sdk-go-v2/docs/sdk-utilities/ec2-imds/

includes the following example snippet:

localip, err := client.GetMetadata(context.TODO(), &imds.GetMetadataInput{
	Path: "local-ipv4",
})
if err != nil {
    log.Printf("Unable to retrieve the private IP address from the EC2 instance: %s\n", err)
    return
}

fmt.Printf("local-ip: %v\n", localip)

However, as already established, because the return value of GetMetadata() is not a string, this example will not produce the expected result:

local-ip: &{0xc000092140 {map[{}:{[{<nil> false false {map[]}}]}]}}

If the caller is responsible for closing GetMetadataOutput.Content, that obligation should probably be stated in the documentation.

The documentation for other functions, like GetUserData(), may also need to be amended.

Version of AWS SDK for Go?

github.com/aws/aws-sdk-go-v2/config v1.1.2
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.3

Version of Go (go version)?

go version go1.16.1 darwin/amd64

Steps to reproduce

Here is an example that works:

package main

import (
	"context"
	"fmt"
	"io"
	"log"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
)

func main() {
	cfg, err := config.LoadDefaultConfig(context.TODO())
	if err != nil {
		log.Fatal(err)
	}

	client := imds.NewFromConfig(cfg)

	res, err := client.GetMetadata(context.TODO(), &imds.GetMetadataInput{
		Path: "instance-id",
	})
	if err != nil {
		log.Fatal(err)
	}
	defer res.Content.Close()
	id, err := io.ReadAll(res.Content)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("instance-id: %s\n", id)
}
@skmcgrail
Copy link
Member

Thanks for bring this to our attention @saj, we will get this updated in our next documentation refresh.

@skmcgrail skmcgrail self-assigned this Mar 16, 2021
@skmcgrail skmcgrail added documentation This is a problem with documentation. bug This issue is a bug. labels Mar 16, 2021
@github-actions
Copy link

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 17, 2022
@jasdel jasdel removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 17, 2022
@skmcgrail skmcgrail removed their assignment Oct 24, 2022
@RanVaknin RanVaknin added p3 This is a minor priority issue s Effort estimation: small labels Nov 4, 2022
@RanVaknin RanVaknin added the queued This issues is on the AWS team's backlog label May 2, 2024
@lucix-aws lucix-aws linked a pull request Sep 11, 2024 that will close this issue
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. documentation This is a problem with documentation. p3 This is a minor priority issue queued This issues is on the AWS team's backlog s Effort estimation: small
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants