@byaga/cdk-patterns 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/FunctionIntegration.d.ts +6 -2
- package/lib/FunctionIntegration.js +5 -1
- package/lib/RestApi.d.ts +1 -1
- package/lib/RestApi.js +3 -1
- package/package.json +1 -1
- package/src/FunctionIntegration.ts +12 -2
- package/src/RestApi.ts +13 -11
@@ -1,6 +1,6 @@
|
|
1
1
|
import { DeployStack } from "./DeployStack";
|
2
2
|
import { Function, FunctionProps } from "aws-cdk-lib/aws-lambda";
|
3
|
-
import { JsonSchema, MethodOptions } from "aws-cdk-lib/aws-apigateway";
|
3
|
+
import { JsonSchema, MethodOptions, Method } from "aws-cdk-lib/aws-apigateway";
|
4
4
|
import { Duration } from "aws-cdk-lib";
|
5
5
|
import { RestApi } from "./RestApi";
|
6
6
|
interface AddToApiOptions {
|
@@ -16,6 +16,10 @@ export declare class FunctionIntegration extends Function {
|
|
16
16
|
stack: DeployStack;
|
17
17
|
name: string;
|
18
18
|
constructor(stack: DeployStack, id: string, options: FunctionIntegrationProps);
|
19
|
-
attach(api: RestApi, httpMethod: string, path: string, props?: AddToApiOptions):
|
19
|
+
attach(api: RestApi, httpMethod: string, path: string, props?: AddToApiOptions): ApiAttachPoint;
|
20
|
+
}
|
21
|
+
interface ApiAttachPoint {
|
22
|
+
method: Method;
|
23
|
+
resourceArn: string;
|
20
24
|
}
|
21
25
|
export {};
|
@@ -26,7 +26,7 @@ class FunctionIntegration extends aws_lambda_1.Function {
|
|
26
26
|
exportName: stack.genName(id, 'function-name')
|
27
27
|
});
|
28
28
|
}
|
29
|
-
attach(api, httpMethod, path, props) {
|
29
|
+
attach(api, httpMethod, path, props = {}) {
|
30
30
|
const resource = api.path(path);
|
31
31
|
const integration = new aws_apigateway_1.LambdaIntegration(this, {
|
32
32
|
requestTemplates: {
|
@@ -38,6 +38,10 @@ class FunctionIntegration extends aws_lambda_1.Function {
|
|
38
38
|
if (schema)
|
39
39
|
options = applySchema(this.stack, this.name, schema, options, resource);
|
40
40
|
const method = resource.addMethod(httpMethod, integration, options);
|
41
|
+
return {
|
42
|
+
method,
|
43
|
+
resourceArn: `arn:aws:execute-api:${this.stack.region}:${this.stack.account}:${api.restApiId}/${this.stack.stage}/${httpMethod}${path}`
|
44
|
+
};
|
41
45
|
}
|
42
46
|
}
|
43
47
|
exports.FunctionIntegration = FunctionIntegration;
|
package/lib/RestApi.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { RestApi as RestApiBase
|
1
|
+
import { IDomainName, IResource, RestApi as RestApiBase } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { DeployStack } from "./DeployStack";
|
3
3
|
import { ICorsConfig } from "./ICorsConfig";
|
4
4
|
import { PolicyStatement } from "aws-cdk-lib/aws-iam";
|
package/lib/RestApi.js
CHANGED
@@ -127,7 +127,9 @@ class RestApi extends aws_apigateway_1.RestApi {
|
|
127
127
|
return policyStatement;
|
128
128
|
}
|
129
129
|
path(uri) {
|
130
|
-
const { node } = uri.split('/')
|
130
|
+
const { node } = uri.split('/')
|
131
|
+
.filter(path => !!path)
|
132
|
+
.reduce((resource, path) => {
|
131
133
|
if (!resource.children[path]) {
|
132
134
|
resource.children[path] = {
|
133
135
|
children: {},
|
package/package.json
CHANGED
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
MethodOptions,
|
7
7
|
Model,
|
8
8
|
RequestValidator,
|
9
|
-
IResource
|
9
|
+
IResource, Method
|
10
10
|
} from "aws-cdk-lib/aws-apigateway";
|
11
11
|
import {CfnOutput, Duration} from "aws-cdk-lib";
|
12
12
|
import {applyHoneycombToLambda} from "./methods/apply-honeycomb-to-lambda";
|
@@ -47,7 +47,7 @@ export class FunctionIntegration extends Function {
|
|
47
47
|
});
|
48
48
|
}
|
49
49
|
|
50
|
-
attach(api: RestApi, httpMethod: string, path: string, props
|
50
|
+
attach(api: RestApi, httpMethod: string, path: string, props: AddToApiOptions = {}) : ApiAttachPoint {
|
51
51
|
const resource: IResource = api.path(path)
|
52
52
|
const integration = new LambdaIntegration(this, {
|
53
53
|
requestTemplates: {
|
@@ -60,6 +60,11 @@ export class FunctionIntegration extends Function {
|
|
60
60
|
if (schema) options = applySchema(this.stack, this.name, schema, options, resource)
|
61
61
|
|
62
62
|
const method = resource.addMethod(httpMethod, integration, options)
|
63
|
+
|
64
|
+
return {
|
65
|
+
method,
|
66
|
+
resourceArn: `arn:aws:execute-api:${this.stack.region}:${this.stack.account}:${api.restApiId}/${this.stack.stage}/${httpMethod}${path}`
|
67
|
+
};
|
63
68
|
}
|
64
69
|
}
|
65
70
|
|
@@ -80,4 +85,9 @@ function applySchema(stack: DeployStack, name: string, schema: JsonSchema, optio
|
|
80
85
|
})
|
81
86
|
}
|
82
87
|
}
|
88
|
+
}
|
89
|
+
|
90
|
+
interface ApiAttachPoint {
|
91
|
+
method: Method
|
92
|
+
resourceArn: string
|
83
93
|
}
|
package/src/RestApi.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import {
|
2
|
-
RestApi as RestApiBase,
|
3
2
|
BasePathMapping,
|
4
3
|
ContentHandling,
|
5
4
|
DomainName,
|
6
5
|
EndpointType,
|
7
|
-
MockIntegration,
|
8
6
|
IDomainName,
|
9
|
-
IResource
|
7
|
+
IResource,
|
8
|
+
MockIntegration,
|
9
|
+
RestApi as RestApiBase
|
10
10
|
} from "aws-cdk-lib/aws-apigateway";
|
11
11
|
import {DeployStack} from "./DeployStack"
|
12
12
|
import {ICorsConfig} from "./ICorsConfig";
|
@@ -163,15 +163,17 @@ export class RestApi extends RestApiBase {
|
|
163
163
|
}
|
164
164
|
|
165
165
|
path(uri: string): IResource {
|
166
|
-
const {node} = uri.split('/')
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
166
|
+
const {node} = uri.split('/')
|
167
|
+
.filter(path => !!path)
|
168
|
+
.reduce((resource, path) => {
|
169
|
+
if (!resource.children[path]) {
|
170
|
+
resource.children[path] = {
|
171
|
+
children: {},
|
172
|
+
node: resource.node.addResource(path)
|
173
|
+
}
|
171
174
|
}
|
172
|
-
|
173
|
-
|
174
|
-
}, this._tree);
|
175
|
+
return resource.children[path];
|
176
|
+
}, this._tree);
|
175
177
|
|
176
178
|
return node
|
177
179
|
}
|