Skip to content

Commit

Permalink
Make region in AWS Lambda configurable for cross-region notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamJHall committed Dec 5, 2023
1 parent f15b234 commit 99813a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/graphql-mesh-server/assets/handlers/notify-sns.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PublishCommand, SNSClient } from "@aws-sdk/client-sns";
import { SNSEvent } from "aws-lambda";

const client = new SNSClient({ region: process.env.AWS_REGION });
const client = new SNSClient({ region: process.env.REGION });

export const handler = async (event: SNSEvent): Promise<void> => {
const record = event.Records[0];
Expand Down
5 changes: 5 additions & 0 deletions packages/graphql-mesh-server/lib/graphql-mesh-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export type MeshHostingProps = {
* ARN of the SNS Topic to send deployment notifications to
*/
notificationArn?: string;
/**
* Region of the SNS Topic that deployment notifications are sent to
*/
notificationRegion?: string;
/**
* List of IPv4 addresses to block
*/
Expand Down Expand Up @@ -186,6 +190,7 @@ export class MeshHosting extends Construct {
repository: this.repository,
service: this.service,
notificationArn: props.notificationArn,
notificationRegion: props.notificationRegion,
});

new PerformanceMetrics(this, "cloudwatch", {
Expand Down
8 changes: 7 additions & 1 deletion packages/graphql-mesh-server/lib/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Duration } from "aws-cdk-lib";
import { Duration, Stack } from "aws-cdk-lib";
import { Artifact, Pipeline } from "aws-cdk-lib/aws-codepipeline";
import { Repository } from "aws-cdk-lib/aws-ecr";
import { FargateService } from "aws-cdk-lib/aws-ecs";
Expand Down Expand Up @@ -38,6 +38,11 @@ export interface CodePipelineServiceProps {
* ARN of the SNS Topic to send deployment notifications to
*/
notificationArn?: string;

/**
* AWS Region the SNS topic is deployed in
*/
notificationRegion?: string;
}

export class CodePipelineService extends Construct {
Expand Down Expand Up @@ -115,6 +120,7 @@ export class CodePipelineService extends Construct {
timeout: Duration.seconds(10),
environment: {
SNS_TOPIC: props.notificationArn,
REGION: props.notificationRegion || Stack.of(this).region,
},
});

Expand Down

0 comments on commit 99813a4

Please sign in to comment.