Skip to content

Commit 14d43b8

Browse files
committed
improve async calls using aws sdk
1 parent 19f5630 commit 14d43b8

File tree

14 files changed

+5373
-4811
lines changed

14 files changed

+5373
-4811
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ If you are using this package to build resource providers for CloudFormation, in
2222

2323
**Installation**
2424

25-
Because this is a developer preview, you still need to install the plugin using [pip](https://pypi.org/project/pip/) from GitHub.
25+
Because this is a developer preview, you still need to install the plugin from GitHub using [pip](https://pypi.org/project/pip/).
2626

2727
```shell
2828
pip3 install git+https://github.com/eduardomourar/cloudformation-cli-typescript-plugin.git#egg=cloudformation-cli-typescript-plugin
@@ -94,7 +94,7 @@ pip3 install \
9494

9595
That ensures neither is accidentally installed from PyPI.
9696

97-
Linting and running unit tests is done via [pre-commit](https://pre-commit.com/), and so is performed automatically on commit after being installed (`pre-commit install`). The continuous integration also runs these checks. Manual options are available so you don't have to commit:
97+
Linting and running unit tests is done via [pre-commit](https://pre-commit.com/), and so is performed automatically on commit after being installed (`pre-commit install`).
9898

9999
```shell
100100
# run all hooks on all files, mirrors what the CI runs

package-lock.json

Lines changed: 5183 additions & 4658 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
{
2-
"name": "cfn-rpdk",
3-
"version": "0.0.1",
4-
"description": "The CloudFormation Resource Provider Development Kit (RPDK) allows you to author your own resource providers that can be used by CloudFormation. This plugin library helps to provide runtime bindings for the execution of your providers by CloudFormation.",
5-
"main": "dist/index.js",
6-
"directories": {
7-
"test": "tests"
8-
},
9-
"files": [
10-
"dist"
11-
],
12-
"scripts": {
13-
"build": "npx tsc",
14-
"prepack": "npm run build",
15-
"test": "npx jest",
16-
"test:debug": "npx --node-arg=--inspect jest --runInBand",
17-
"test:ci": "npx jest --ci --collect-coverage"
18-
},
19-
"engines": {
20-
"node": ">=10.0.0",
21-
"npm": ">=5.6.0"
22-
},
23-
"repository": {
24-
"type": "git",
25-
"url": "git+https://github.com/eduardomourar/cloudformation-cli-typescript-plugin.git"
26-
},
27-
"author": "eduardomourar",
28-
"license": "MIT",
29-
"bugs": {
30-
"url": "https://github.com/eduardomourar/cloudformation-cli-typescript-plugin/issues"
31-
},
32-
"homepage": "https://github.com/eduardomourar/cloudformation-cli-typescript-plugin#readme",
33-
"dependencies": {
34-
"autobind-decorator": "^2.4.0",
35-
"reflect-metadata": "^0.1.13",
36-
"tombok": "https://github.com/eduardomourar/tombok/releases/download/v0.0.1/tombok-0.0.1.tar.gz",
37-
"uuid": "^7.0.2"
38-
},
39-
"devDependencies": {
40-
"@types/aws-sdk": "^2.7.0",
41-
"@types/jest": "^25.1.0",
42-
"@types/node": "^12.0.0",
43-
"@types/uuid": "^7.0.0",
44-
"jest": "^25.1.0",
45-
"ts-jest": "^25.3.0",
46-
"typescript": "^3.8.3"
47-
},
48-
"optionalDependencies": {
49-
"aws-sdk": "^2.656.0"
50-
}
2+
"name": "cfn-rpdk",
3+
"version": "0.0.2",
4+
"description": "The CloudFormation Resource Provider Development Kit (RPDK) allows you to author your own resource providers that can be used by CloudFormation. This plugin library helps to provide runtime bindings for the execution of your providers by CloudFormation.",
5+
"main": "dist/index.js",
6+
"directories": {
7+
"test": "tests"
8+
},
9+
"files": [
10+
"dist"
11+
],
12+
"scripts": {
13+
"build": "npx tsc",
14+
"prepack": "npm run build",
15+
"test": "npx jest",
16+
"test:debug": "npx --node-arg=--inspect jest --runInBand",
17+
"test:ci": "npx jest --ci --collect-coverage"
18+
},
19+
"engines": {
20+
"node": ">=10.0.0",
21+
"npm": ">=5.6.0"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "git+https://github.com/eduardomourar/cloudformation-cli-typescript-plugin.git"
26+
},
27+
"author": "eduardomourar",
28+
"license": "MIT",
29+
"bugs": {
30+
"url": "https://github.com/eduardomourar/cloudformation-cli-typescript-plugin/issues"
31+
},
32+
"homepage": "https://github.com/eduardomourar/cloudformation-cli-typescript-plugin#readme",
33+
"dependencies": {
34+
"autobind-decorator": "^2.4.0",
35+
"reflect-metadata": "^0.1.13",
36+
"tombok": "https://github.com/eduardomourar/tombok/releases/download/v0.0.1/tombok-0.0.1.tar.gz",
37+
"uuid": "^7.0.2"
38+
},
39+
"devDependencies": {
40+
"@types/aws-sdk": "^2.7.0",
41+
"@types/jest": "^25.1.0",
42+
"@types/node": "^12.0.0",
43+
"@types/uuid": "^7.0.0",
44+
"jest": "^25.3.0",
45+
"minimist": ">=1.2.5",
46+
"ts-jest": "^25.4.0",
47+
"typescript": "^3.8.3"
48+
},
49+
"optionalDependencies": {
50+
"aws-sdk": "^2.656.0"
51+
}
5152
}
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES6",
4-
"module": "commonjs",
5-
"noImplicitAny": true,
6-
"alwaysStrict": true,
7-
"esModuleInterop": true,
8-
"moduleResolution": "node",
9-
"allowJs": true,
10-
"experimentalDecorators": true,
11-
"outDir": "dist"
12-
},
13-
"include": ["src/**/*.ts"],
14-
"exclude": ["node_modules"]
2+
"compilerOptions": {
3+
"target": "ES2017",
4+
"module": "commonjs",
5+
"noImplicitAny": true,
6+
"alwaysStrict": true,
7+
"esModuleInterop": true,
8+
"moduleResolution": "node",
9+
"allowJs": true,
10+
"experimentalDecorators": true,
11+
"outDir": "dist"
12+
},
13+
"include": [
14+
"src/**/*.ts"
15+
],
16+
"exclude": [
17+
"node_modules"
18+
]
1519
}

python/rpdk/typescript/templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const progress: ProgressEvent = ProgressEvent.builder()
3030
// Required on IN_PROGRESS
3131
// The number of seconds to delay before re-invocation
3232
.callbackDelaySeconds(0)
33-
33+
3434
.build()
3535
```
3636

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"name": "{{ name }}",
3-
"version": "1.0.0",
4-
"description": "{{ description }}",
5-
"main": "dist/handlers.js",
6-
"files": [
7-
"dist"
8-
],
9-
"scripts": {
10-
"build": "npx tsc",
11-
"prepack": "npm run build",
12-
"test": "echo \"Error: no test specified\" && exit 1"
13-
},
14-
"dependencies": {
15-
"{{lib_name}}": "https://github.com/eduardomourar/cloudformation-cli-typescript-plugin/releases/download/v0.0.1/cfn-rpdk-0.0.1.tgz"
16-
},
17-
"devDependencies": {
18-
"@types/node": "^12.0.0",
19-
"typescript": "^3.8.3"
20-
},
21-
"optionalDependencies": {
22-
"aws-sdk": "^2.656.0"
23-
}
2+
"name": "{{ name }}",
3+
"version": "1.0.0",
4+
"description": "{{ description }}",
5+
"main": "dist/handlers.js",
6+
"files": [
7+
"dist"
8+
],
9+
"scripts": {
10+
"build": "npx tsc",
11+
"prepack": "npm run build",
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
14+
"dependencies": {
15+
"{{lib_name}}": "https://github.com/eduardomourar/cloudformation-cli-typescript-plugin/releases/download/v0.0.1/cfn-rpdk-0.0.1.tgz"
16+
},
17+
"devDependencies": {
18+
"@types/node": "^12.0.0",
19+
"typescript": "^3.8.3"
20+
},
21+
"optionalDependencies": {
22+
"aws-sdk": "^2.656.0"
23+
}
2424
}

src/callback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ export async function reportProgress(options: ProgressOptions): Promise<void> {
4444
if (response['ResponseMetadata']) {
4545
requestId = response.ResponseMetadata.RequestId;
4646
}
47-
LOGGER.debug(`Record Handler Progress with Request Id ${requestId} and Request: ${JSON.stringify(request)}`);
47+
LOGGER.debug(`Record Handler Progress with Request Id ${requestId} and Request:`, request);
4848
}
4949
}

src/metrics.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function formatDimensions(dimensions: Map<string, string>): Array<Dimensi
1313
formatted.push({
1414
Name: key,
1515
Value: value,
16-
})
16+
});
1717
});
1818
return formatted;
1919
}
@@ -43,6 +43,7 @@ export class MetricPublisher {
4343
Value: value,
4444
}],
4545
}).promise();
46+
LOGGER.debug('Response from "putMetricData"', metric);
4647
} catch(err) {
4748
LOGGER.error(`An error occurred while publishing metrics: ${err.message}`);
4849
}
@@ -63,72 +64,76 @@ export class MetricsPublisherProxy {
6364
const suffix = resourceType.replace(/::/g, '/');
6465
return `${METRIC_NAMESPACE_ROOT}/${accountId}/${suffix}`;
6566
}
66-
67+
6768
addMetricsPublisher(session?: SessionProxy): void {
6869
if (session) {
6970
this.publishers.push(new MetricPublisher(session, this.namespace));
7071
}
7172
}
7273

73-
publishExceptionMetric(timestamp: Date, action: Action, error: Error): void {
74+
async publishExceptionMetric(timestamp: Date, action: Action, error: Error): Promise<any> {
7475
const dimensions = new Map<string, string>();
7576
dimensions.set('DimensionKeyActionType', action);
76-
dimensions.set('DimensionKeyExceptionType', error.constructor.name);
77+
dimensions.set('DimensionKeyExceptionType', error['errorCode'] || error.constructor.name);
7778
dimensions.set('DimensionKeyResourceType', this.resourceType);
78-
this.publishers.forEach((publisher: MetricPublisher) => {
79-
publisher.publishMetric(
79+
const promises: Array<Promise<void>> = this.publishers.map((publisher: MetricPublisher) => {
80+
return publisher.publishMetric(
8081
MetricTypes.HandlerException,
8182
dimensions,
8283
StandardUnit.Count,
8384
1.0,
8485
timestamp,
8586
);
8687
});
88+
return await Promise.all(promises);
8789
}
8890

89-
publishInvocationMetric(timestamp: Date, action: Action): void {
91+
async publishInvocationMetric(timestamp: Date, action: Action): Promise<any> {
9092
const dimensions = new Map<string, string>();
9193
dimensions.set('DimensionKeyActionType', action);
9294
dimensions.set('DimensionKeyResourceType', this.resourceType);
93-
this.publishers.forEach((publisher: MetricPublisher) => {
94-
publisher.publishMetric(
95+
const promises: Array<Promise<void>> = this.publishers.map((publisher: MetricPublisher) => {
96+
return publisher.publishMetric(
9597
MetricTypes.HandlerInvocationCount,
9698
dimensions,
9799
StandardUnit.Count,
98100
1.0,
99101
timestamp,
100102
);
101103
});
104+
return await Promise.all(promises);
102105
}
103106

104-
publishDurationMetric(timestamp: Date, action: Action, milliseconds: number): void {
107+
async publishDurationMetric(timestamp: Date, action: Action, milliseconds: number): Promise<any> {
105108
const dimensions = new Map<string, string>();
106109
dimensions.set('DimensionKeyActionType', action);
107110
dimensions.set('DimensionKeyResourceType', this.resourceType);
108-
this.publishers.forEach((publisher: MetricPublisher) => {
109-
publisher.publishMetric(
111+
const promises: Array<Promise<void>> = this.publishers.map((publisher: MetricPublisher) => {
112+
return publisher.publishMetric(
110113
MetricTypes.HandlerInvocationDuration,
111114
dimensions,
112115
StandardUnit.Milliseconds,
113116
milliseconds,
114117
timestamp,
115118
);
116119
});
120+
return await Promise.all(promises);
117121
}
118122

119-
publishLogDeliveryExceptionMetric(timestamp: Date, error: any): void {
123+
async publishLogDeliveryExceptionMetric(timestamp: Date, error: any): Promise<any> {
120124
const dimensions = new Map<string, string>();
121125
dimensions.set('DimensionKeyActionType', 'ProviderLogDelivery');
122-
dimensions.set('DimensionKeyExceptionType', error.constructor.name);
126+
dimensions.set('DimensionKeyExceptionType', error['errorCode'] || error.constructor.name);
123127
dimensions.set('DimensionKeyResourceType', this.resourceType);
124-
this.publishers.forEach((publisher: MetricPublisher) => {
125-
publisher.publishMetric(
128+
const promises: Array<Promise<void>> = this.publishers.map((publisher: MetricPublisher) => {
129+
return publisher.publishMetric(
126130
MetricTypes.HandlerException,
127131
dimensions,
128132
StandardUnit.Count,
129133
1.0,
130134
timestamp,
131135
);
132136
});
137+
return await Promise.all(promises);
133138
}
134139
}

0 commit comments

Comments
 (0)