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

Allow caller to pass in AWS client configuration #34

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

Conversation

smbkr
Copy link

@smbkr smbkr commented Feb 9, 2022

This PR adds an optional second parameter to the EventBridge.build and StepFunctions.build methods, which allows the caller to specify AWS service client configuration. This permits a user to override the default endpoint, timeout, specify a logger, etc.

The behaviour when no client config is specified is the same as the current behaviour.

Closes #31

Usage example:

import { EventBridge } from 'sls-test-tools'

const awsConfig = { endpoint: 'http://localhost:4566', region: 'eu-west-1' } // override the default endpoint so that it can be used against localstack
const localBus = await EventBridge.build('my-local-bus', awsConfig)
const awsBus = await EventBridge.build('aws-bus') // same as current behaviour

The use case for myself is to allow overriding the endpoint as shown above so tests can run against localstack. This will also open up the possibility of writing tests for the library itself using localstack if desired.

@smbkr
Copy link
Author

smbkr commented Feb 9, 2022

Another option is to add an --endpoint= CLI flag like with the region and stack ones, and then in the implementation anywhere new AWSClient.SomeAWSService() is called, pass in the endpoint. This would be similar to the current implementation of src/assertions/toContainItemWithValues/index.ts:11 which does the same with region.

Usage would be something like:

jest '--region=eu-west-1' '--endpoint=http://localhost:4566' --runInBand

and in the implementation, something like:

import { region, endpoint } from '../../helpers/general'

const docClient = new AWSClient.DynamoDB.DocumentClient({
  region, // this is in the current implementation but is not actually required as the region is set globally in `helpers/general.ts`
  endpoint,
});

One problem with the current approach is that it only applies to the EventBridge and StepFunctions helpers. This CLI flag alternative would allow configuring the endpoint for all AWS services, including e.g. the S3 client used in the S3 assertions, the DynamoDB assertions, etc. And I find it a bit more consistent with the existing configuration options.

Thoughts?

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.

Allow configuring AWS endpoint
1 participant