Skip to content
Open
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

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

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

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

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"myapi4C7BF186": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"BinaryMediaTypes": [
"image/png",
"application/pdf"
],
"BodyS3Location": {
"Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
Expand Down Expand Up @@ -518,7 +522,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"myapiDeployment92F2CB491b0e40e722acabc99cc39958c957686d": {
"myapiDeployment92F2CB49a6f2b34c48304b5ea39e505074a5a8ee": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "beta stage",
Expand Down Expand Up @@ -550,7 +554,7 @@
"CacheClusterEnabled": true,
"CacheClusterSize": "0.5",
"DeploymentId": {
"Ref": "myapiDeployment92F2CB491b0e40e722acabc99cc39958c957686d"
"Ref": "myapiDeployment92F2CB49a6f2b34c48304b5ea39e505074a5a8ee"
},
"Description": "beta stage",
"MethodSettings": [
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Test extends cdk.Stack {
apiDefinition: apigateway.ApiDefinition.fromAsset(path.join(__dirname, 'sample-definition.yaml')),
disableExecuteApiEndpoint: true,
minCompressionSize: Size.bytes(1024),
binaryMediaTypes: ['image/png', 'application/pdf'],
retainDeployments: true,
cloudWatchRole: true,
deployOptions: {
Expand Down
9 changes: 9 additions & 0 deletions packages/aws-cdk-lib/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,15 @@ const api = new apigateway.SpecRestApi(this, 'books-api', {
});
```

`SpecRestApi` also supports binary media types, similar to `RestApi`:

```ts
const api = new apigateway.SpecRestApi(this, 'books-api', {
apiDefinition: apigateway.ApiDefinition.fromAsset('path-to-file.json'),
binaryMediaTypes: ['image/png', 'application/pdf']
});
```

### Endpoint configuration

By default, `SpecRestApi` will create an edge optimized endpoint.
Expand Down
9 changes: 9 additions & 0 deletions packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ export interface SpecRestApiProps extends RestApiBaseProps {
*/
readonly apiDefinition: ApiDefinition;

/**
* The list of binary media mime-types that are supported by the RestApi
* resource, such as "image/png" or "application/octet-stream"
*
* @default - RestApi supports only UTF-8-encoded text payloads.
*/
readonly binaryMediaTypes?: string[];

/**
* A Size(in bytes, kibibytes, mebibytes etc) that is used to enable compression (with non-negative
* between 0 and 10485760 (10M) bytes, inclusive) or disable compression
Expand Down Expand Up @@ -802,6 +810,7 @@ export class SpecRestApi extends RestApiBase {
policy: Lazy.any({ produce: () => this.resourcePolicy }),
failOnWarnings: props.failOnWarnings,
minimumCompressionSize: props.minCompressionSize?.toBytes(),
binaryMediaTypes: props.binaryMediaTypes,
body: apiDefConfig.inlineDefinition ?? undefined,
bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location,
endpointConfiguration: this._configureEndpoints(props),
Expand Down
24 changes: 24 additions & 0 deletions packages/aws-cdk-lib/aws-apigateway/test/restapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,30 @@ describe('SpecRestApi', () => {
});
});

test('SpecRestApi binaryMediaTypes', () => {
// GIVEN
const app = new App({
context: {
'@aws-cdk/aws-apigateway:disableCloudWatchRole': true,
},
});

stack = new Stack(app);
const api = new apigw.SpecRestApi(stack, 'SpecRestApi', {
apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }),
binaryMediaTypes: ['image/png', 'application/octet-stream'],
});

// WHEN
api.root.addMethod('GET');

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', {
Name: 'SpecRestApi',
BinaryMediaTypes: ['image/png', 'application/octet-stream'],
});
});

test('"endpointConfiguration" can be used to specify endpoint types for the api', () => {
// WHEN
const api = new apigw.SpecRestApi(stack, 'api', {
Expand Down
Loading