GithubHelp home page GithubHelp logo

elgohr / go-localstack Goto Github PK

View Code? Open in Web Editor NEW
75.0 3.0 18.0 9.96 MB

Go Wrapper for using localstack

License: Apache License 2.0

Go 96.96% Dockerfile 0.52% Makefile 1.57% Shell 0.95%
localstack go golang testing aws golang-library sqs s3 cloudwatch lambda

go-localstack's Introduction

Hi there, I'm Lars ๐Ÿ‘‹

This is the place where I tinker and opensource things.
Projects are not related to my employer.

  • ๐Ÿ”ญ Iโ€™m currently working on trying not to break things ๐Ÿคฃ
  • ๐ŸŒฑ Iโ€™m learning every day
  • ๐Ÿ‘ฏ Iโ€™m looking for inspiring things
  • โšก Fun fact: I made the worlds first Android hand warmer, using C.

Contact me:
๐Ÿ“ซ E-Mail (PGP)
๐Ÿ˜ @[email protected]


My code is used in

Map with global usage

go-localstack's People

Contributors

bajelidze avatar dependabot[bot] avatar elgohr avatar github-actions[bot] avatar hugowetterberg avatar renovate-bot avatar renovate[bot] 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-localstack's Issues

go mod tidy fails

First of all: great library, works pretty smooth! Thanks ๐Ÿ˜„

When I import this dependency I am not able to use go mod tidy anymore.

> go mod tidy
go: finding module for package github.com/elgohr/go-localstack/internal/internalfakes
github.com/elgohr/go-localstack tested by
	github.com/elgohr/go-localstack.test imports
	github.com/elgohr/go-localstack/internal/internalfakes: no matching versions for query "latest"

If I got this correct this fails because the fakes are generated, but not part of the repository source.

Getting different Etag on each new execution of localstack

Getting different ETag on each new execution of localstack, if this is not an issue kindly share suggestions so as to how to get same ETag for a specific S3 object GET operation.

Requirement: While running unit tests, the expected(HARD-CODED) ETag doesn't match ETag received during GET operation.
Code Snippet

                        getObject := s3.GetObjectInput{
				Bucket: aws.String(tt.DataBucket),
				Key:    aws.String(tt.ManifestFilePath),
			}

			res, err := tt.s3Client.GetObjectWithContext(context.Background(), &getObject)
			if err != nil {
				fmt.Println(err.Error())
				if err.Error() != tt.want {
					t.Errorf("Want %s Got %s", tt.want, err.Error())
				}
			}
			eTag := res.ETag // this is always changing on every execution, my requirement is to get same or 
                                                                   constant ETag value.

isRunning fails when docker host responds with fully qualified image names

On some OCI hosts (eg podman), the get container call responds with a fully qualified name: eg docker.io/library/go-localstack:latest. This fails the equality check in isRunning which is expecting an unqualified name (eg go-localstack). As a result calls to Start* fail.

An easy fix would be:

-		if c.Image == imageName {
+		if strings.Contains(c.Image, imageName) {

however that may have false positives.

AWS was not able to validate the provided access credentials

When trying to use EC2 client, I get the following error:

=== RUN   TestEc2
time="2022-06-10T14:18:43-07:00" level=info msg="starting localstack"
time="2022-06-10T14:18:44-07:00" level=info msg="waiting for localstack to start..."
time="2022-06-10T14:19:01-07:00" level=info msg="localstack: finished waiting"
    all_test.go:305: operation error EC2: RunInstances, https response error StatusCode: 401, RequestID: 080f9f11-67d7-4061-86d3-e581551458c1, api error AuthFailure: AWS was not able to validate the provided access credentials
--- FAIL: TestEc2 (18.47s)
FAIL
FAIL    command-line-arguments  19.197s
FAIL

Here is the sample code:

func TestEc2(t *testing.T) {
	os.Setenv("AWS_ACCESS_KEY_ID", "dummy")
	os.Setenv("AWS_SECRET_ACCESS_KEY", "dummy")

	ls, err := localstack.NewInstance()
	if err != nil {
		log.Fatalf("could not connect to docker: %v", err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
	defer cancel()

	if err := ls.StartWithContext(ctx); err != nil {
		log.Fatalf("could not start Localstack: %v", err)
	}

	ec2Client = ec2.NewFromConfig(awsConfig(ctx, ls, localstack.EC2))
       
  	createInstance(t, ec2Client)
}

func awsConfig(ctx context.Context, l *localstack.Instance, s localstack.Service) aws.Config {
	cfg, err := config.LoadDefaultConfig(ctx,
		config.WithRegion("us-east-1"),
		config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(func(_, _ string, options ...interface{}) (aws.Endpoint, error) {
			return aws.Endpoint{
				PartitionID:       "aws",
				URL:               l.EndpointV2(s),
				SigningRegion:     endpoints.UsEast1RegionID,
				HostnameImmutable: true,
			}, nil
		})),
		config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")),
	)

	if err != nil {
		log.Fatalf("could not load config: %v", err)
	}

	return cfg
}

func createInstance(t *testing.T, c *ec2.Client) types.Instance {
	t.Helper()

	result, err := c.RunInstances(
		context.TODO(),
		&ec2.RunInstancesInput{
			ImageId:      aws.String("ami-e7527ed7"),
			InstanceType: types.InstanceTypeT2Micro,
			MinCount:     aws.Int32(1),
			MaxCount:     aws.Int32(1),
		})

	if err != nil {
		t.Fatal(err)
	}

	if result == nil {
		t.Fatal("empty RunInstance result")
	}

	if len(result.Instances) != 1 {
		t.Fatalf("exptected 1 instance, got %d", len(result.Instances))
	}

	return result.Instances[0]
}

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

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.