Skip to content

Commit d30f514

Browse files
authored
Merge branch 'main' into TheRealAmazonKendra/pr-linter
2 parents 9d984ae + a4364ce commit d30f514

12 files changed

Lines changed: 2431 additions & 1 deletion

packages/@aws-cdk/aws-apigateway/lib/restapi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ export class SpecRestApi extends RestApiBase {
652652
bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location,
653653
endpointConfiguration: this._configureEndpoints(props),
654654
parameters: props.parameters,
655+
disableExecuteApiEndpoint: props.disableExecuteApiEndpoint,
655656
});
656657

657658
props.apiDefinition.bindAfterCreate(this, this);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as path from 'path';
2+
import * as lambda from '@aws-cdk/aws-lambda';
3+
import * as cdk from '@aws-cdk/core';
4+
import { IntegTest } from '@aws-cdk/integ-tests';
5+
import * as apigateway from '../lib';
6+
7+
class Test extends cdk.Stack {
8+
constructor(scope: cdk.App, id: string) {
9+
super(scope, id);
10+
11+
const api = new apigateway.SpecRestApi(this, 'my-api', {
12+
apiDefinition: apigateway.ApiDefinition.fromAsset(path.join(__dirname, 'sample-definition.yaml')),
13+
disableExecuteApiEndpoint: true,
14+
retainDeployments: true,
15+
cloudWatchRole: true,
16+
deployOptions: {
17+
cacheClusterEnabled: true,
18+
stageName: 'beta',
19+
description: 'beta stage',
20+
loggingLevel: apigateway.MethodLoggingLevel.INFO,
21+
dataTraceEnabled: true,
22+
methodOptions: {
23+
'/api/appliances/GET': {
24+
cachingEnabled: true,
25+
},
26+
},
27+
},
28+
});
29+
30+
const handler = new lambda.Function(this, 'MyHandler', {
31+
runtime: lambda.Runtime.NODEJS_14_X,
32+
code: lambda.Code.fromInline(`exports.handler = ${handlerCode}`),
33+
handler: 'index.handler',
34+
});
35+
36+
const v1 = api.root.addResource('v1');
37+
38+
const integration = new apigateway.LambdaIntegration(handler);
39+
40+
const toys = v1.addResource('toys');
41+
const getToysMethod: apigateway.Method = toys.addMethod('GET', integration, { apiKeyRequired: true });
42+
toys.addMethod('POST');
43+
toys.addMethod('PUT');
44+
45+
const appliances = v1.addResource('appliances');
46+
appliances.addMethod('GET');
47+
48+
const books = v1.addResource('books');
49+
books.addMethod('GET', integration);
50+
books.addMethod('POST', integration);
51+
52+
function handlerCode(event: any, _: any, callback: any) {
53+
return callback(undefined, {
54+
isBase64Encoded: false,
55+
statusCode: 200,
56+
headers: { 'content-type': 'application/json' },
57+
body: JSON.stringify(event),
58+
});
59+
}
60+
61+
const key = api.addApiKey('ApiKey');
62+
const plan = api.addUsagePlan('UsagePlan', {
63+
name: 'Basic',
64+
apiKey: key,
65+
description: 'Free tier monthly usage plan',
66+
throttle: { rateLimit: 5 },
67+
quota: {
68+
limit: 10000,
69+
period: apigateway.Period.MONTH,
70+
},
71+
});
72+
plan.addApiStage({
73+
stage: api.deploymentStage,
74+
throttle: [
75+
{
76+
method: getToysMethod,
77+
throttle: {
78+
rateLimit: 10,
79+
burstLimit: 2,
80+
},
81+
},
82+
],
83+
});
84+
}
85+
}
86+
87+
const app = new cdk.App();
88+
89+
const testCase = new Test(app, 'test-apigateway-spec-restapi');
90+
new IntegTest(app, 'apigateway-spec-restapi', {
91+
testCases: [testCase],
92+
});

packages/@aws-cdk/aws-apigateway/test/restapi.test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,21 @@ describe('restapi', () => {
11501150
});
11511151
});
11521152

1153-
test('"disableExecuteApiEndpoint" can disable the default execute-api endpoint', () => {
1153+
test('disableExecuteApiEndpoint is false when set to false in RestApi', () => {
1154+
// GIVEN
1155+
const stack = new Stack();
1156+
1157+
// WHEN
1158+
const api = new apigw.RestApi(stack, 'my-api', { disableExecuteApiEndpoint: false });
1159+
api.root.addMethod('GET');
1160+
1161+
// THEN
1162+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', {
1163+
DisableExecuteApiEndpoint: false,
1164+
});
1165+
});
1166+
1167+
test('disableExecuteApiEndpoint is true when set to true in RestApi', () => {
11541168
// GIVEN
11551169
const stack = new Stack();
11561170

@@ -1164,6 +1178,39 @@ describe('restapi', () => {
11641178
});
11651179
});
11661180

1181+
test('disableExecuteApiEndpoint is false when set to false in SpecRestApi', () => {
1182+
// GIVEN
1183+
const stack = new Stack();
1184+
1185+
// WHEN
1186+
const api = new apigw.SpecRestApi(stack, 'my-api', {
1187+
apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }),
1188+
disableExecuteApiEndpoint: false,
1189+
});
1190+
api.root.addMethod('GET');
1191+
1192+
// THEN
1193+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', {
1194+
DisableExecuteApiEndpoint: false,
1195+
});
1196+
});
1197+
1198+
test('disableExecuteApiEndpoint is true when set to true in SpecRestApi', () => {
1199+
// GIVEN
1200+
const stack = new Stack();
1201+
1202+
// WHEN
1203+
const api = new apigw.SpecRestApi(stack, 'my-api', {
1204+
apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }),
1205+
disableExecuteApiEndpoint: true,
1206+
});
1207+
api.root.addMethod('GET');
1208+
1209+
// THEN
1210+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::RestApi', {
1211+
DisableExecuteApiEndpoint: true,
1212+
});
1213+
});
11671214

11681215
describe('Description', () => {
11691216
test('description can be set', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "21.0.0",
3+
"files": {
4+
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
5+
"source": {
6+
"path": "apigatewayspecrestapiDefaultTestDeployAssertD16AA485.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Parameters": {
3+
"BootstrapVersion": {
4+
"Type": "AWS::SSM::Parameter::Value<String>",
5+
"Default": "/cdk-bootstrap/hnb659fds/version",
6+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
7+
}
8+
},
9+
"Rules": {
10+
"CheckBootstrapVersion": {
11+
"Assertions": [
12+
{
13+
"Assert": {
14+
"Fn::Not": [
15+
{
16+
"Fn::Contains": [
17+
[
18+
"1",
19+
"2",
20+
"3",
21+
"4",
22+
"5"
23+
],
24+
{
25+
"Ref": "BootstrapVersion"
26+
}
27+
]
28+
}
29+
]
30+
},
31+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
32+
}
33+
]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: "3.0.2"
2+
info:
3+
version: 1.0.0
4+
title: Test API for CDK
5+
paths:
6+
/pets:
7+
get:
8+
summary: Test Method
9+
operationId: testMethod
10+
responses:
11+
"200":
12+
description: A paged array of pets
13+
content:
14+
application/json:
15+
schema:
16+
$ref: "#/components/schemas/Empty"
17+
x-amazon-apigateway-integration:
18+
responses:
19+
default:
20+
statusCode: "200"
21+
requestTemplates:
22+
application/json: "{\"statusCode\": 200}"
23+
passthroughBehavior: when_no_match
24+
type: mock
25+
26+
components:
27+
schemas:
28+
Empty:
29+
title: Empty Schema
30+
type: object
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"21.0.0"}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "21.0.0",
3+
"testCases": {
4+
"apigateway-spec-restapi/DefaultTest": {
5+
"stacks": [
6+
"test-apigateway-spec-restapi"
7+
],
8+
"assertionStack": "apigateway-spec-restapi/DefaultTest/DeployAssert",
9+
"assertionStackName": "apigatewayspecrestapiDefaultTestDeployAssertD16AA485"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)