Skip to content

Connect to AWS

Settings.AWS is required. It is a awsclient.Source, which yields the aws.Config the adapter builds its SQS and SNS clients from. The adapter has no credentials or region settings of its own.

From the ambient chain

import "gitlab.com/phpboyscout/go/awsclient"

backend := sqs.FIFO(sqs.Settings{
    AWS: awsclient.Ambient(awsclient.WithRegion("eu-west-2")),
})

Ambient resolves the SDK's default chain (environment, shared config and profile, SSO, instance or task role) the first time it is asked, once, and shares the result. It does no work when you call it. The adapter asks when the backend is opened, which the bus does at Start, so a chain that cannot resolve fails there and not at construction.

awsclient.PerCall() resolves afresh on every ask. The adapter asks once per Open, so the two differ little here. awsclient.WithLoadOptions passes the SDK's own load options, such as a profile or an assumed role, through to the chain.

Region

There is no default region, here or in awsclient. A config that names none is awsclient.ErrNoRegion. Pass awsclient.WithRegion, or set AWS_REGION.

From a config you already built

src, err := awsclient.FromConfig(cfg) // cfg is an aws.Config
if err != nil {
    return err // awsclient.ErrNoRegion if cfg.Region is empty
}

backend := sqs.Standard(sqs.Settings{AWS: src})

FromConfig checks the region at once and loads nothing.

Point it at LocalStack

Either set AWS_ENDPOINT_URL for the process, as the tutorial does with awsclient.Ambient, or build the config with a base endpoint, as the adapter's own suite does:

cfg := aws.Config{
    Region:       "us-east-1",
    Credentials:  credentials.NewStaticCredentialsProvider("test", "test", ""),
    BaseEndpoint: aws.String("http://127.0.0.1:4566"),
}

src, err := awsclient.FromConfig(cfg)

What Open does and fails on

Open resolves the config and builds an SQS client and an SNS client. It makes no call to either service and binds no topic or queue, because a topology is per subject and a subject is not known until Subscribe or Publish names one. So bad credentials, a wrong endpoint or a missing queue show at the first Subscribe or Publish, not at Open.

Cause Error
Settings.AWS is nil messaging-sqs: Settings.AWS is required; use awsclient.Ambient() or FromConfig
the source cannot resolve a config messaging-sqs: resolving the AWS configuration, wrapping the cause, awsclient.ErrNoRegion among them

Both are returned by Open and are not sentinels of this module.

What the identity needs

The adapter's calls, and so the IAM permissions behind them, are in AWS calls it makes.