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

accessanalyzer - region not being read? #1260

Closed
3 tasks done
akingscote opened this issue May 14, 2021 · 6 comments · Fixed by #1349
Closed
3 tasks done

accessanalyzer - region not being read? #1260

akingscote opened this issue May 14, 2021 · 6 comments · Fixed by #1349
Labels
bug This issue is a bug.

Comments

@akingscote
Copy link

akingscote commented May 14, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
I cannot figure out how to use the DeleteAnalyzer action and am leaning towards the issue being a bug.
Ive dont have any problem using the SDK for other resources.

It seems that the region is never passed to the functions so errors out. Ive set it in numerous places, as well as the AWS_REGION and AWS_DEFAULT_REGION variables.

Version of AWS SDK for Go?
Example: v1.29.22
1.5.0
Version of Go (go version)?
go version go1.16.3 linux/amd64

To Reproduce (observed behavior)
Steps to reproduce the behavior (please share code or minimal repo)

        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)

Results in the following error:

failed to call service: AccessAnalyzer, operation: DeleteAnalyzer, error: failed to resolve service endpoint, an AWS region is required, but was not found 

Similarly if i dont provide the resolver, i get a similar error.
If i add a resolver URL...

Trying some other stuff...

        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)

Which returns the following error:

requestID: 85f3d4ca-dc1b-43a4-9272-a05adea0f9d7, error: api error InvalidSignatureException: Credential should be scoped to a valid region, not ''.  
failed to call service: AccessAnalyzer, operation: DeleteAnalyzer, error: https response error StatusCode: 403, RequestID: 85f3d4ca-dc1b-43a4-9272-a05adea0f9d7, api error InvalidSignatureException: Credential should be scoped to a valid region, not ''.  

Ive tried a load of different things but cannot for the life of me delete an access analyzer.
Please provide some insight into what im missing here. The documentation is lacking any examples and I couldnt see any unit tests to reverse engineer.

Expected behavior
Id expect the access analyzer to be deleted.

@akingscote akingscote added the bug This issue is a bug. label May 14, 2021
@roneli
Copy link

roneli commented May 24, 2021

I hit the same problem with list analyzers, seems like the region isn't added to the stack i.e in the InvokeOperation in access analyzer functions for example List Analyzer is missing this middleware to be added:

func newServiceMetadataMiddleware_opListAnalyzers(region string) *awsmiddleware.RegisterServiceMetadata { return &awsmiddleware.RegisterServiceMetadata{ Region: region, ServiceID: ServiceID, SigningName: "access-analyzer", OperationName: "ListAnalyzers", } }
and then added to the stack middleware functions

I think adding to the middleware stack like this:

analyzerAwsCfg.APIOptions =  append(awsCfg.APIOptions, func(stack *middleware.Stack) error {
		if err := stack.Initialize.Add(	&awsmiddleware.RegisterServiceMetadata{
			Region:        region,
			ServiceID:     accessanalyzer.ServiceID,
			SigningName:   "access-analyzer",
			OperationName: "ListAnalyzers",
		}, middleware.Before); err != nil {
			return err
		}
		return nil
	})

should work buts a little hacky workaround.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@skmcgrail skmcgrail reopened this Jul 19, 2021
@skmcgrail
Copy link
Member

Re-opning this until we cut a new release with the merged fix.

@Skarlso
Copy link

Skarlso commented Aug 25, 2021

Can I ask when this will be fixed please? This is quite serious as in blocking me from using v2 completely. :/

@jasdel
Copy link
Contributor

jasdel commented Nov 3, 2021

This issue should be fixed now, and you can updater to the latest version of the SDK to get the correct behavior. Please reopen if this issue if you're still having issues.

@jasdel jasdel closed this as completed Nov 3, 2021
@github-actions
Copy link

github-actions bot commented Nov 3, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

disq added a commit to disq/cloudquery that referenced this issue Sep 1, 2022
disq added a commit to disq/cloudquery that referenced this issue Sep 5, 2022
disq added a commit to cloudquery/cloudquery that referenced this issue Sep 6, 2022
disq added a commit to cloudquery/cloudquery that referenced this issue Sep 8, 2022
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.
Projects
None yet
5 participants