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

Added credential provider example #1438

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

siennathesane
Copy link

Added a credential provider example for the AWS for Go SDK v2. There is a matching PR with the complete code at localstack/localstack-aws-sdk-examples#9.

Signed-off-by: Sienna Satterwhite <[email protected]>
Copy link

⚡️ Deploying PR Preview...

@gregfurman gregfurman self-requested a review August 21, 2024 07:56
@gregfurman
Copy link
Contributor

Hey. Thanks for this! I'm always a fan of Golang + LocalStack getting more love 😄

Couple of remarks on this. First, the CI is failing becase of linting issues (see failed job here). Also maybe give the best practices a lookthrough which could help diagnose/fix this.

In addition, I think for the purposes of documentation, it would probably be a better idea to provide users' with a simpler minimum-viable-solution. While what this PR proposes would obviously work, I'm concerned perhaps the scope is a bit large.

What about something like this?

const (
	AwsLocalEndpoint        = "http://localhost:4566"
	AwsLocalCredentialsName = "AwsLocalCredentials"
	AwsLocalDefaultRegion   = "us-east-1"
	AwsLocalAccountId       = "000000000000"
	AwsLocalAccessKey       = "test"
	AwsLocalSecret          = "test"
)

func main() {
	// build an aws.Credential-compliant configuration
	localstackCredentials := aws.Credentials{
		AccessKeyID:     AwsLocalAccessKey,
		SecretAccessKey: AwsLocalSecret,
		SessionToken:    "SESSION",
		Source:          "LocalStack hardcoded credentials.",
	}

	awsCfg, err := config.LoadDefaultConfig(context.TODO(),
		config.WithCredentialsProvider(credentials.StaticCredentialsProvider{
			Value: localstackCredentials,
		}),
		config.WithDefaultRegion(AwsLocalDefaultRegion),
		// Optionally, add more LoadOptions...
	)

	// ...

}

It could probably be slimmed down even further to just focus on the credential provider.

What are your thoughts?

@siennathesane
Copy link
Author

The matching PR in the examples repo contains all the necessary code, so I don't think this update is required. I included it since it's a common use case, but I don't feel strongly about this PR. Feel free to update or close it, I'm fine with either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants