I am trying to delete an IAM Access Analyzer using V2 of the Go SDK, but I keep getting the following issue:
failed to call service: AccessAnalyzer, operation: DeleteAnalyzer, error: failed to resolve service endpoint, an AWS region is required, but was not found
I am not having issues using the SDK for resources under other services. My code is as follows, with the region set by env variables as per this documentation:
name := "myanalyzer"
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithSharedConfigProfile(profile),
config.WithRegion("eu-west-1"),
)
if err != nil {
log.Fatalln("Error loading configuration", err)
}
resolver := accessanalyzer.NewDefaultEndpointResolver()
client := accessanalyzer.NewFromConfig(cfg, func(o *accessanalyzer.Options) {
o.Region = "eu-west-1"
o.EndpointOptions = options
o.EndpointResolver = resolver
})
input := &accessanalyzer.DeleteAnalyzerInput{
AnalyzerName: &name,
}
result, err := client.DeleteAnalyzer(context.TODO(), input)
I have also tried to specify a resolver URL:
name := "myanalyzer"
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithSharedConfigProfile(profile),
config.WithRegion("eu-west-1"),
)
if err != nil {
log.Fatalln("Error loading configuration", err)
}
resolver := accessanalyzer.EndpointResolverFromURL("https://access-analyzer.eu-west-1.amazonaws.com")
client := accessanalyzer.NewFromConfig(cfg, func(o *accessanalyzer.Options) {
o.Region = "eu-west-1"
o.EndpointOptions = options
o.EndpointResolver = resolver
})
input := &accessanalyzer.DeleteAnalyzerInput{
AnalyzerName: &name,
}
result, err := client.DeleteAnalyzer(context.TODO(), input)
This does not work either, returning an error of
requestID: 85f3d4ca-dc1b-43a4-9272-a05adea0f9d7, error: api error InvalidSignatureException: Credential should be scoped to a valid region, not ''.
How can I provide the region so that the analyzer can be deleted? Any help would be much appreciated.
AWS SDK Go version: 1.5.0, Go version: 1.16.3 linux/amd64