Git Product home page Git Product logo

go-aws-ssm's People

Contributors

geototti21 avatar ingshtrom avatar rhnvrm avatar rlankfo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-aws-ssm's Issues

Migrate from aws.Config v1 to v2

tempConfig, _ := awsConfigV2.LoadDefaultConfig(context.TODO())
paramStore, _ := awsParamStore.NewParameterStore(&tempConfig)

cannot use &tempConfig (value of type *"github.com/aws/aws-sdk-go-v2/aws".Config) as *"github.com/aws/aws-sdk-go/aws".Config value in argument to awsParamStore.NewParameterStore

How i can use default config like from ~/.aws/credentials or like v2 LoadDefaultConfig(context.TODO()) for setup keys without store in code?

Trying to read parameter store value greater than 512 bytes into viper returns 'While parsing config: unexpected end of JSON input` error

Hi,

I'm storing a relatively large value in AWS Param Store that is greater than 512 bytes. What I'm seeing is that when I try to fetch that value from Param Store, it gets the full value, but when I try to feed that value into viper using viper.ReadConfig(params) it only feeds the first 512 bytes of the param value.

Code:

params, err = ssm.GetAllParametersByPath(ssmPath, true)
if err != nil {
    return
}

// inspecting the individual params here shows that the full value has been captured

err = viper.ReadConfig(params)
// err returned: While parsing config: unexpected end of JSON input

I've pinpointed where the error is coming from:
In buffer.go, the minimum size of the buffer initialized in buffer.ReadFrom(r io.Reader) is 512 bytes. It is suppose to automatically increase the size of the buffer when it gets to that predefined size and doesn't find an EOF char during r.Read(...):

// Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond
// what is required to hold the contents of r, ReadFrom will not grow the
// underlying buffer.
const MinRead = 512

// ReadFrom reads data from r until EOF and appends it to the buffer, growing
// the buffer as needed. The return value n is the number of bytes read. Any
// error except io.EOF encountered during the read is also returned. If the
// buffer becomes too large, ReadFrom will panic with ErrTooLarge.
func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error) {
	b.lastRead = opInvalid
	for {
		i := b.grow(MinRead)
		b.buf = b.buf[:i]
		m, e := r.Read(b.buf[i:cap(b.buf)])
		if m < 0 {
			panic(errNegativeRead)
		}

		b.buf = b.buf[:i+m]
		n += int64(m)
		if e == io.EOF {
			return n, nil // e is EOF, so return nil explicitly
		}
		if e != nil {
			return n, e
		}
	}
}

parameter.go implements the io.Reader's Read like so:

func (p *Parameters) Read(des []byte) (n int, err error) {
	bytesJSON, err := json.Marshal(p.getKeyValueMap())
	if err != nil {
		return 0, err
	}
	return copy(des, bytesJSON), io.EOF
}

This means that we are returning an io.EOF regardless of if we've read the full param value.

So we return the first 512 bytes back to buffer.ReadFrom(...) along with the io.EOF, which buffer.ReadFrom(..) interprets as being finished with the full message, so it doesn't try to enlarge the buffer and read more of the value, thus chopping off the end of the value (including the end JSON }), which is why we end up with the unexpected end of JSON content error.

The limit on the value as described by AWS for Param Store entries is 8Kb for advanced keys or 4Kb for normal keys, so I felt I should bring this issue to the repo's owners attention.

Hope you are having a good day!

New session with options

Hi, i tried the basic usage, but it does not get the default region unfortunately. So, i added the region as;

pmstore, err := awsssm.NewParameterStore(aws.NewConfig().WithRegion("eu-west-1"))

Like this, it works. But i don't want to pass region in code. And way to do it, we need create NewSessionWithOptions and enable the SharedConfig, as;

func NewParameterStore(ssmConfig ...*aws.Config) (*ParameterStore, error) {

sessionAWS, err := session.NewSessionWithOptions(session.Options{
	SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
	return nil, err
}
svc := ssm.New(sessionAWS)
return &ParameterStore{ssm: svc}, nil 

}

Is there any way to do it without manipulating this function ?

Issue with copy in method Read.

Got issue here because in my case bytesJSON has 790 bytes but viper uses default bytes.Buffer with MinRead = 512 and io.EOF on line 44 means that my JSON will be corrupted. So looks like Read must be implemented in better way...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.