Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(custom-resources): support region for AwsCustomResource #4298

Merged
merged 3 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
const call: AwsSdkCall | undefined = event.ResourceProperties[event.RequestType];

if (call) {
const awsService = new (AWS as any)[call.service](call.apiVersion && { apiVersion: call.apiVersion });
const awsService = new (AWS as any)[call.service]({
apiVersion: call.apiVersion,
region: call.region,
});

try {
const response = await awsService[call.action](call.parameters && decodeBooleans(call.parameters)).promise();
flatData = flatten(response);
flatData = {
apiVersion: awsService.config.apiVersion, // For test purposes: check if apiVersion was correctly passed.
region: awsService.config.region, // For test purposes: check if region was correctly passed.
...flatten(response),
};
data = call.outputPath
? filterKeys(flatData, k => k.startsWith(call.outputPath!))
: flatData;
Expand Down
17 changes: 13 additions & 4 deletions packages/@aws-cdk/custom-resources/lib/aws-custom-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface AwsSdkCall {
* resource id. Either `physicalResourceId` or `physicalResourceIdPath`
* must be specified for onCreate or onUpdate calls.
*
* @default no path
* @default - no path
*/
readonly physicalResourceIdPath?: string;

Expand All @@ -51,7 +51,7 @@ export interface AwsSdkCall {
* `physicalResourceId` or `physicalResourceIdPath` must be specified for
* onCreate or onUpdate calls.
*
* @default no physical resource id
* @default - no physical resource id
*/
readonly physicalResourceId?: string;

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

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

/**
* The region to send service requests to.
* **Note: Cross-region operations are generally considered an anti-pattern.**
* **Consider first deploying a stack in that region.**
*
* @default - the region where this custom resource is deployed
*/
readonly region?: string;

/**
* Restrict the data returned by the custom resource to a specific path in
* the API response. Use this to limit the data returned by the custom
Expand Down
Loading