Where is the EC2 API #2019
Replies: 4 comments
-
Hi @daryl-williams, The error you received is a generic Golang error and not an error with the SDK itself. If you are new to Golang I suggest taking a look at the official getting started docs. In terms of the import path, the url to the ec2 service is https://github.com/aws/aws-sdk-go-v2/tree/main/service/ec2 if you are looking at the main branch, however the go compiler requires the HEAD in a generic route to that package.
Let me know if you have any other questions. |
Beta Was this translation helpful? Give feedback.
-
Hi @RanVaknin <https://github.com/RanVaknin>,
Thanks for your reply, I appreciate it. While I am no Golang guru I have some small experience and am familiar with the generic "package main is not in GOROOT” error. It is my understanding that this error can happen when a package cannot be found via the import path, and given that the documentation example (https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/gov2/ec2/common/DescribeInstancesv2.go) uses the import path of "github.com/aws/aws-sdk-go-v2/service/ec2 <http://github.com/aws/aws-sdk-go-v2/service/ec2>” and when I got an error building the example I researched the issue and was unable to find the uri in the example import path and, I guess I jumped to a conclusion, my bad I guess. However I tried using the import path you suggested and I still get an error using the import path "github.com/aws/aws-sdk-go-v2/tree/main/service/ec2” <http://github.com/aws/aws-sdk-go-v2/tree/main/service/ec2%E2%80%9D:> , these are the steps I took after adding the new import path:
$ go build .
main.go:12:9: no required module provides package github.com/aws/aws-sdk-go-v2/tree/main/service/ec2; to add it:
go get github.com/aws/aws-sdk-go-v2/tree/main/service/ec2 <http://github.com/aws/aws-sdk-go-v2/tree/main/service/ec2>
$ go get github.com/aws/aws-sdk-go-v2/tree/main/service/ec2
go: module ***@***.*** found (v1.17.4), but does not contain package github.com/aws/aws-sdk-go-v2/tree/main/service/ec2 <http://github.com/aws/aws-sdk-go-v2/tree/main/service/ec2>
So I am still not clear on what is going on. Your help is much appreciated.
Regards
Daryl
… On Feb 13, 2023, at 15:24, Ran Vaknin ***@***.***> wrote:
Hi @daryl-williams <https://github.com/daryl-williams>,
The error you received is a generic Golang error and not an error with the SDK itself. If you are new to Golang I suggest taking a look at the official getting started <https://go.dev/doc/tutorial/getting-started> docs.
If not, I would check out this stackoverflow thread <https://stackoverflow.com/questions/61845013/package-xxx-is-not-in-goroot-when-building-a-go-project> it has some in depth explanation on how to get solve the package main is not in GOROOT error.
In terms of the import path, the url to the ec2 service is https://github.com/aws/aws-sdk-go-v2/tree/main/service/ec2 if you are looking at the main branch, however the go compiler requires the HEAD in a generic route to that package.
As a package author, you must adhere to the stable HEAD philosophy. Your default branch must always be the stable, released version of your package. You must do work in feature branches and only merge when ready to release.
Let me know if you have any other questions.
Thanks,
Ran~
—
Reply to this email directly, view it on GitHub <#2019 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAH7A5KA743VOWBLZ2QBXW3WXK7DZANCNFSM6AAAAAAUY6LBSA>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
Hi @daryl-williams , Sorry, I was unclear. My whole spiel was about trying to explain that the reason why your initial The correct import is For example here is a snippet I was just using to test some instance reservation functionality. package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ec2"
)
func main() {
cfg, _ := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
client := ec2.NewFromConfig(cfg)
input := &ec2.DescribeInstancesInput{}
instances, err := client.DescribeInstances(context.Background(), input)
if err != nil {
panic(err)
}
for _, r := range instances.Reservations {
fmt.Println("Reservation ID: " + *r.ReservationId)
fmt.Println("Instance IDs:")
for _, i := range r.Instances {
fmt.Println(" " + *i.InstanceId)
}
fmt.Println("")
}
} Thanks and good luck. |
Beta Was this translation helpful? Give feedback.
-
Hi @RanVaknin <https://github.com/RanVaknin>,
Thank you very much, your example works great, it’s just what I needed. I appreciate your help!
Thanks,
Daryl
… On Feb 13, 2023, at 16:01, Ran Vaknin ***@***.***> wrote:
Hi @daryl-williams <https://github.com/daryl-williams> ,
Sorry, I was unclear. My whole spiel was about trying to explain that the reason why your initial wget -O - call didnt work.
just ignore what I said.
The correct import is github.com/aws/aws-sdk-go-v2/service/ec2 *notice its missing the https in the beginning.
For example here is a snippet I was just using to test some instance reservation functionality.
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ec2"
)
func main() {
cfg, _ := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
client := ec2.NewFromConfig(cfg)
input := &ec2.DescribeInstancesInput{}
instances, err := client.DescribeInstances(context.Background(), input)
if err != nil {
panic(err)
}
for _, r := range instances.Reservations {
fmt.Println("Reservation ID: " + *r.ReservationId)
fmt.Println("Instance IDs:")
for _, i := range r.Instances {
fmt.Println(" " + *i.InstanceId)
}
fmt.Println("")
}
}
Thanks and good luck.
Ran~
—
Reply to this email directly, view it on GitHub <#2019 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAH7A5ME7U7MD6V5YYE7GFLWXLDNXANCNFSM6AAAAAAUY6LBSA>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
Greeting All,
I would like to start using the AWS EC2 API to automate certain functionality but I am unable to find the import path from the documentation: "github.com/aws/aws-sdk-go-v2/service/ec2" and this is causing an error when trying to build the code: package main is not in GOROOT (/snap/go/10030/src/main)
In my project directory I have the files:
$ ls -l
total 12
-rw-r--r-- 1 ubuntu ubuntu 917 Feb 11 14:38 go.mod
-rw-r--r-- 1 ubuntu ubuntu 3487 Feb 11 14:38 go.sum
-rw-r--r-- 1 ubuntu ubuntu 2156 Feb 11 14:55 main.go
I do not have GO environment variables set:
$ env | grep -I GO
$
and when I try to build:
$ go build main
package main is not in GOROOT (/snap/go/10030/src/main)
and if I try to look at import path from the docs:
$ wget -O - https://github.com/aws/aws-sdk-go-v2/service/ec2
--2023-02-11 15:08:47-- https://github.com/aws/aws-sdk-go-v2/service/ec2
Resolving github.com (github.com)... 192.30.255.112
Connecting to github.com (github.com)|192.30.255.112|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2023-02-11 15:08:47 ERROR 404: Not Found.
Any hep would be much appreciated.
Best Regards,
Daryl
Beta Was this translation helpful? Give feedback.
All reactions