/**
* Shared AWS clients. Reuse one client per service to avoid per-request creation.
*/
import { S3Client } from "@aws-sdk/client-s3";
import { EC2Client } from "@aws-sdk/client-ec2";
import { STSClient } from "@aws-sdk/client-sts";
import { IAMClient } from "@aws-sdk/client-iam";
import { CloudTrailClient } from "@aws-sdk/client-cloudtrail";
import { CloudWatchClient } from "@aws-sdk/client-cloudwatch";
import { CostExplorerClient } from "@aws-sdk/client-cost-explorer";
import { GuardDutyClient } from "@aws-sdk/client-guardduty";
import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
import { HealthClient } from "@aws-sdk/client-health";
import { ACMClient } from "@aws-sdk/client-acm";
import { RDSClient } from "@aws-sdk/client-rds";
import { LambdaClient } from "@aws-sdk/client-lambda";
import { BackupClient } from "@aws-sdk/client-backup";
import { BudgetsClient } from "@aws-sdk/client-budgets";
import { ElasticLoadBalancingV2Client } from "@aws-sdk/client-elastic-load-balancing-v2";
import { WAFV2Client } from "@aws-sdk/client-wafv2";
import { SNSClient } from "@aws-sdk/client-sns";
import { Route53Client } from "@aws-sdk/client-route-53";
import { ECSClient } from "@aws-sdk/client-ecs";
import { EKSClient } from "@aws-sdk/client-eks";
import { AutoScalingClient } from "@aws-sdk/client-auto-scaling";
import { CloudFrontClient } from "@aws-sdk/client-cloudfront";
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
import { SSMClient } from "@aws-sdk/client-ssm";
import { CloudFormationClient } from "@aws-sdk/client-cloudformation";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { SupportClient } from "@aws-sdk/client-support";
import { getAwsClientOptions } from "./lib/config.js";
// Default clients (use default region from env)
const defaultOpts = getAwsClientOptions();
export const s3Client = new S3Client(defaultOpts);
export const ec2Client = new EC2Client(defaultOpts);
export const stsClient = new STSClient(defaultOpts);
export const iamClient = new IAMClient(defaultOpts);
export const cloudTrailClient = new CloudTrailClient(defaultOpts);
export const cloudWatchClient = new CloudWatchClient(defaultOpts);
export const costExplorerClient = new CostExplorerClient(defaultOpts);
export const guardDutyClient = new GuardDutyClient(defaultOpts);
export const cloudWatchLogsClient = new CloudWatchLogsClient(defaultOpts);
export const healthClient = new HealthClient({
...defaultOpts,
region: "us-east-1",
});
export const acmClient = new ACMClient(defaultOpts);
export const rdsClient = new RDSClient(defaultOpts);
export const lambdaClient = new LambdaClient(defaultOpts);
export const backupClient = new BackupClient(defaultOpts);
export const budgetsClient = new BudgetsClient(defaultOpts);
export const elbv2Client = new ElasticLoadBalancingV2Client(defaultOpts);
export const wafv2Client = new WAFV2Client(defaultOpts);
export const snsClient = new SNSClient(defaultOpts);
export const route53Client = new Route53Client(defaultOpts);
export const ecsClient = new ECSClient(defaultOpts);
export const eksClient = new EKSClient(defaultOpts);
export const asgClient = new AutoScalingClient(defaultOpts);
export const cloudFrontClient = new CloudFrontClient(defaultOpts);
export const secretsManagerClient = new SecretsManagerClient(defaultOpts);
export const ssmClient = new SSMClient(defaultOpts);
export const cfnClient = new CloudFormationClient(defaultOpts);
export const dynamoDbClient = new DynamoDBClient(defaultOpts);
export const supportClient = new SupportClient({
...defaultOpts,
region: "us-east-1",
});
/** Get a region-specific EC2 client (for tools that support region override). */
export function getEc2Client(region?: string): EC2Client {
if (!region) return ec2Client;
return new EC2Client(getAwsClientOptions(region));
}
/** Get a region-specific RDS client. */
export function getRdsClient(region?: string): RDSClient {
if (!region) return rdsClient;
return new RDSClient(getAwsClientOptions(region));
}
/** Get a region-specific Lambda client. */
export function getLambdaClient(region?: string): LambdaClient {
if (!region) return lambdaClient;
return new LambdaClient(getAwsClientOptions(region));
}