Skip to content

Instantly share code, notes, and snippets.

@titouancreach
Created August 8, 2024 07:30
Show Gist options
  • Save titouancreach/9688661a0e1fd698ffd21f22e533a8bd to your computer and use it in GitHub Desktop.
Save titouancreach/9688661a0e1fd698ffd21f22e533a8bd to your computer and use it in GitHub Desktop.
import { SQSClient } from '@aws-sdk/client-sqs'
import { Config, Context, Effect, Layer } from 'effect'
const makeSqsClient = Effect.gen(function* () {
const awsAccessKeyId = yield* Config.string('AWS_ACCESS_KEY_ID').pipe(
Config.withDescription('AWS Access Key ID'),
)
const awsSecretAccessKey = yield* Config.string('AWS_SECRET_ACCESS_KEY').pipe(
Config.withDescription('AWS Secret'),
)
const awsRegion = yield* Config.string('AWS_REGION').pipe(
Config.withDescription('AWS Region'),
Config.withDefault('eu-west-1'), // paris
)
const client = new SQSClient({
region: awsRegion,
credentials: {
accessKeyId: awsAccessKeyId,
secretAccessKey: awsSecretAccessKey,
},
})
return client
})
export class SqsClient extends Context.Tag('SqsClient')<
SqsClient,
Effect.Effect.Success<typeof makeSqsClient>
>() {
static Live = Layer.effect(this, makeSqsClient)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment