Skip to content

Commit 934d36f

Browse files
jogoldmergify[bot]
authored andcommitted
fix(custom-resources): support region for AwsCustomResource (#4298)
* fix(custom-resources): support region for AwsCustomResource Allow to specify region for AWS API calls in `AwsCustomResource` Remove gitignored file `lib/sdk-api-metadata.json`. Closes #4292 * add warning note in region doc
1 parent 68e1e85 commit 934d36f

File tree

4 files changed

+59
-776
lines changed

4 files changed

+59
-776
lines changed

packages/@aws-cdk/custom-resources/lib/aws-custom-resource-provider/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,18 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
6262
const call: AwsSdkCall | undefined = event.ResourceProperties[event.RequestType];
6363

6464
if (call) {
65-
const awsService = new (AWS as any)[call.service](call.apiVersion && { apiVersion: call.apiVersion });
65+
const awsService = new (AWS as any)[call.service]({
66+
apiVersion: call.apiVersion,
67+
region: call.region,
68+
});
6669

6770
try {
6871
const response = await awsService[call.action](call.parameters && decodeBooleans(call.parameters)).promise();
69-
flatData = flatten(response);
72+
flatData = {
73+
apiVersion: awsService.config.apiVersion, // For test purposes: check if apiVersion was correctly passed.
74+
region: awsService.config.region, // For test purposes: check if region was correctly passed.
75+
...flatten(response),
76+
};
7077
data = call.outputPath
7178
? filterKeys(flatData, k => k.startsWith(call.outputPath!))
7279
: flatData;

packages/@aws-cdk/custom-resources/lib/aws-custom-resource.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface AwsSdkCall {
4242
* resource id. Either `physicalResourceId` or `physicalResourceIdPath`
4343
* must be specified for onCreate or onUpdate calls.
4444
*
45-
* @default no path
45+
* @default - no path
4646
*/
4747
readonly physicalResourceIdPath?: string;
4848

@@ -51,7 +51,7 @@ export interface AwsSdkCall {
5151
* `physicalResourceId` or `physicalResourceIdPath` must be specified for
5252
* onCreate or onUpdate calls.
5353
*
54-
* @default no physical resource id
54+
* @default - no physical resource id
5555
*/
5656
readonly physicalResourceId?: string;
5757

@@ -60,18 +60,27 @@ export interface AwsSdkCall {
6060
* `Error` object will be tested against this pattern. If there is a match an
6161
* error will not be thrown.
6262
*
63-
* @default do not catch errors
63+
* @default - do not catch errors
6464
*/
6565
readonly catchErrorPattern?: string;
6666

6767
/**
6868
* API version to use for the service
6969
*
7070
* @see https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/locking-api-versions.html
71-
* @default use latest available API version
71+
* @default - use latest available API version
7272
*/
7373
readonly apiVersion?: string;
7474

75+
/**
76+
* The region to send service requests to.
77+
* **Note: Cross-region operations are generally considered an anti-pattern.**
78+
* **Consider first deploying a stack in that region.**
79+
*
80+
* @default - the region where this custom resource is deployed
81+
*/
82+
readonly region?: string;
83+
7584
/**
7685
* Restrict the data returned by the custom resource to a specific path in
7786
* the API response. Use this to limit the data returned by the custom

0 commit comments

Comments
 (0)