aws-sdk-go-wrapper icon indicating copy to clipboard operation
aws-sdk-go-wrapper copied to clipboard

[RFC] Allow use of profiles

Open DavidGamba opened this issue 5 years ago • 5 comments

This one is to just get your eyes on it.

The way you are doing your session creation doesn't allow for many options. Our setup is a multi account setup where we use access keys defined in the root account and assume roles to access multiple other accounts.

In other cases we use ec2 instances with instance profiles to run our automation from.

Splitting the session creation from the resource creation allows the caller to bring custom session needs.

DavidGamba avatar Mar 13 '20 06:03 DavidGamba

Codecov Report

Merging #57 into master will decrease coverage by 0.71%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
- Coverage    42.2%   41.48%   -0.72%     
==========================================
  Files          59       59              
  Lines        4109     4180      +71     
==========================================
  Hits         1734     1734              
- Misses       2264     2335      +71     
  Partials      111      111
Impacted Files Coverage Δ
config/config.go 58.49% <0%> (-25.3%) :arrow_down:
sqs/client.go 58.53% <0%> (-3.01%) :arrow_down:
cloudwatch/client.go 18.75% <0%> (-5.25%) :arrow_down:
cloudwatch/request_type.go 0% <0%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a8a27a0...dbaa8f5. Read the comment docs.

codecov-io avatar Mar 13 '20 06:03 codecov-io

Coverage Status

Coverage decreased (-0.2%) to 42.46% when pulling dbaa8f59428fe99bb07701320641a2a786abfd3b on DavidGamba:allow-use-of-profiles into 6ddcc8fd83b6bda66f5b1713b87d822444790f8e on evalphobia:master.

coveralls avatar Mar 13 '20 06:03 coveralls

Coverage Status

Coverage decreased (-0.2%) to 42.46% when pulling dbaa8f59428fe99bb07701320641a2a786abfd3b on DavidGamba:allow-use-of-profiles into 6ddcc8fd83b6bda66f5b1713b87d822444790f8e on evalphobia:master.

coveralls avatar Mar 13 '20 06:03 coveralls

@DavidGamba Thank you for your patience and suggestion!

It's a good idea to use the session that you want. What about Config struct directly have AWS session? If it have the session, you don't have to change the constructor of each services. (e.g. sqs.New(conf))

/* config.go */

type Config struct {
	Session *session.Session

	AccessKey string
	...
}

 // Session creates AWS session from the Config values.
func (c Config) Session() (*session.Session, error) {
	if c.Session != nil {
		return c.Session, nil
	}
	return session.NewSession(c.AWSConfig())
}
/* sqs.go */

// New returns initialized *SQS.
func New(conf config.Config) (*SQS, error) {
	sess, err := conf.Session()
	if err != nil {
		return nil, err
	}
	...
}

evalphobia avatar Apr 02 '20 00:04 evalphobia

Hi @evalphobia sorry for the long delay in answering.

It looks good, I need to give it a try but I wont be able to get to that in a couple of weeks.

DavidGamba avatar Apr 06 '20 16:04 DavidGamba