Skip to content

Commit

Permalink
setup aws-ses client
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jan 24, 2025
1 parent 6c7441c commit c084d5a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
22 changes: 21 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"dependencies": {
"@aws-sdk/client-sesv2": "^3.734.0",
"@sentry/cloudflare": "^8.51.0",
"mimetext": "^3.0.27"
"mimetext": "^3.0.27",
"reflect-metadata": "^0.2.2",
"tsyringe-neo": "^5.1.0"
}
}
6 changes: 6 additions & 0 deletions src/app/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Config {
constructor(
public readonly awsAccessKeyId: string,
public readonly awsSecretAccessKey: string,
) {}
}
32 changes: 32 additions & 0 deletions src/app/container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { SESv2Client } from "@aws-sdk/client-sesv2";
import {
container,
DependencyContainer,
instanceCachingFactory,
} from "tsyringe-neo";

import { Config } from "./config";

container.register(SESv2Client, {
useFactory: instanceCachingFactory((c) => {
const config = c.resolve<Config>(Config);

return new SESv2Client({
region: "ap-northeast-1",
credentials: {
accessKeyId: config.awsAccessKeyId,
secretAccessKey: config.awsSecretAccessKey,
},
});
}),
});

export function getContainer(env: Env): DependencyContainer {
const c = container.createChildContainer();

c.register(Config, {
useValue: new Config(env.AWS_ACCESS_KEY_ID, env.AWS_SECRET_ACCESS_KEY),
});

return c;
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "reflect-metadata";

import { withSentry } from "./vendor/sentry";

export default withSentry(
Expand Down
10 changes: 7 additions & 3 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Generated by Wrangler
// After adding bindings to `wrangler.json`, regenerate this interface via `npm run cf-typegen`
// Generated by Wrangler by running `wrangler types`

interface Env {
OPENAI_GATEWAY: string;
STORE: KVNamespace;
SENTRY_DSN: string;
AWS_ACCESS_KEY_ID: string;
AWS_SECRET_ACCESS_KEY: string;
OPENAI_API_KEY: string;
CF_VERSION_METADATA: { id: string; tag: string };
}

0 comments on commit c084d5a

Please sign in to comment.