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

feat(apigateway): integrate with aws services in a different region #13251

Merged
merged 5 commits into from
Feb 24, 2021
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
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ book.addMethod('GET', getBookIntegration, {
});
```

It is possible to also integrate with AWS services in a different region. The following code integrates with Amazon SQS in the
`eu-west-1` region.

```ts
const getMessageIntegration = new apigateway.AwsIntegration({
service: 'sqs',
path: 'queueName',
region: 'eu-west-1'
});
```

## API Keys

The following example shows how to use an API Key with a usage plan:
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export interface AwsIntegrationProps {
* Integration options, such as content handling, request/response mapping, etc.
*/
readonly options?: IntegrationOptions

/**
* The region of the integrated AWS service.
*
* @default - same region as the stack
*/
readonly region?: string;
}

/**
Expand Down Expand Up @@ -87,6 +94,7 @@ export class AwsIntegration extends Integration {
resource: apiType,
sep: '/',
resourceName: apiValue,
region: props.region,
});
},
}),
Expand Down
29 changes: 29 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/method.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,35 @@ describe('method', () => {

});

test('integration can be set for a service in the provided region', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigw.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: false });

// WHEN
new apigw.Method(stack, 'my-method', {
httpMethod: 'POST',
resource: api.root,
integration: new apigw.AwsIntegration({ service: 'sqs', path: 'queueName', region: 'eu-west-1' }),
});

// THEN
expect(stack).toHaveResource('AWS::ApiGateway::Method', {
Integration: {
IntegrationHttpMethod: 'POST',
Type: 'AWS',
Uri: {
'Fn::Join': [
'',
[
'arn:', { Ref: 'AWS::Partition' }, ':apigateway:eu-west-1:sqs:path/queueName',
],
],
},
},
});
});

test('integration with a custom http method can be set via a property', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down