Skip to content

Commit

Permalink
Read organizations endpoint region from environment variable
Browse files Browse the repository at this point in the history
The region should be available in ORGANIZATIONS_ENDPOINT_REGION, but it
defaults to us-east-1 if the value is missing.
  • Loading branch information
mbergkvist committed Mar 11, 2024
1 parent 12ca493 commit 836629e
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/account-provider/is-complete-handler.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as AWS from "aws-sdk";
import { Organizations } from "aws-sdk";

let organizationsClient: AWS.Organizations;
const organizationsRegion = process.env.ORGANIZATIONS_ENDPOINT_REGION ?? "us-east-1";

/**
* The isComplete handler is repeatedly invoked checking CreateAccountStatus until SUCCEEDED or FAILED.
Expand All @@ -15,7 +16,7 @@ export async function handler(event: IsCompleteRequest): Promise<IsCompleteRespo
console.log(`Request of type ${event.RequestType} received`);

if (!organizationsClient) {
organizationsClient = new AWS.Organizations({ region: "us-east-1" });
organizationsClient = new AWS.Organizations({ region: organizationsRegion });
}

console.log("Payload: %j", event);
Expand Down
3 changes: 2 additions & 1 deletion src/account-provider/on-event-handler.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CdkCustomResourceEvent as OnEventRequest, CdkCustomResourceResponse as
import { Organizations } from "aws-sdk";

let organizationsClient: Organizations;
const organizationsRegion = process.env.ORGANIZATIONS_ENDPOINT_REGION ?? "us-east-1";

/**
* The onEvent handler is invoked whenever a resource lifecycle event for an Account occurs
Expand All @@ -12,7 +13,7 @@ export async function handler(event: OnEventRequest): Promise<OnEventResponse> {
console.log(`Request of type ${event.RequestType} received`);

if (!organizationsClient) {
organizationsClient = new Organizations({ region: "us-east-1" });
organizationsClient = new Organizations({ region: organizationsRegion });
}

console.log("Payload: %j", event);
Expand Down
3 changes: 2 additions & 1 deletion src/organization-provider/on-event-handler.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CdkCustomResourceEvent as OnEventRequest, CdkCustomResourceResponse as
import { AWSError, Organizations } from "aws-sdk";

let organizationsClient: Organizations;
const organizationsRegion = process.env.ORGANIZATIONS_ENDPOINT_REGION ?? "us-east-1";

/**
* The onEvent handler is invoked whenever a resource lifecycle event for an organization occurs
Expand All @@ -12,7 +13,7 @@ export async function handler(event: OnEventRequest): Promise<OnEventResponse> {
console.log(`Request of type ${event.RequestType} received`);

if (!organizationsClient) {
organizationsClient = new Organizations({ region: "us-east-1" });
organizationsClient = new Organizations({ region: organizationsRegion });
}

console.log("Payload: %j", event);
Expand Down
3 changes: 2 additions & 1 deletion src/organizational-unit-provider/on-event-handler.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CdkCustomResourceEvent as OnEventRequest, CdkCustomResourceResponse as
import { AWSError, Organizations } from "aws-sdk";

let organizationsClient: Organizations;
const organizationsRegion = process.env.ORGANIZATIONS_ENDPOINT_REGION ?? "us-east-1";

/**
* The onEvent handler is invoked whenever a resource lifecycle event for an organizational unit occurs
Expand All @@ -12,7 +13,7 @@ export const handler = async (event: OnEventRequest): Promise<OnEventResponse> =
console.log(`Request of type ${event.RequestType} received`);

if (!organizationsClient) {
organizationsClient = new Organizations({ region: "us-east-1" });
organizationsClient = new Organizations({ region: organizationsRegion });
}

console.log("Payload: %j", event);
Expand Down
3 changes: 2 additions & 1 deletion src/tag-resource-provider/on-event-handler.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CdkCustomResourceEvent as OnEventRequest, CdkCustomResourceResponse as
import { Organizations } from "aws-sdk";

let organizationsClient: Organizations;
const organizationsRegion = process.env.ORGANIZATIONS_ENDPOINT_REGION ?? "us-east-1";

/**
* The onEvent handler is invoked whenever a resource lifecycle event for a TagResource occurs
Expand All @@ -12,7 +13,7 @@ export async function handler(event: OnEventRequest): Promise<OnEventResponse> {
console.log(`Request of type ${event.RequestType} received`);

if (!organizationsClient) {
organizationsClient = new Organizations({ region: "us-east-1" });
organizationsClient = new Organizations({ region: organizationsRegion });
}

console.log("Payload: %j", event);
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/account.test.ts.snap

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

4 changes: 2 additions & 2 deletions test/__snapshots__/delegated-administrator.test.ts.snap

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

12 changes: 6 additions & 6 deletions test/__snapshots__/dependency-chain.test.ts.snap

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

4 changes: 2 additions & 2 deletions test/__snapshots__/enable-policy-type.test.ts.snap

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

8 changes: 4 additions & 4 deletions test/__snapshots__/integ.default.test.ts.snap

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

4 changes: 2 additions & 2 deletions test/__snapshots__/organization.test.ts.snap

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

6 changes: 3 additions & 3 deletions test/__snapshots__/organizational-unit.test.ts.snap

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

4 changes: 2 additions & 2 deletions test/__snapshots__/policy-attachment.test.ts.snap

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

2 changes: 1 addition & 1 deletion test/__snapshots__/policy.test.ts.snap

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

2 changes: 1 addition & 1 deletion test/__snapshots__/tag-resource.test.ts.snap

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

0 comments on commit 836629e

Please sign in to comment.