@webda/aws 4.0.0-beta.1 → 4.0.0-beta.3
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/README.md +64 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -1
- package/lib/services/aws-parameters.d.ts +33 -0
- package/lib/services/aws-parameters.d.ts.map +1 -0
- package/lib/services/aws-parameters.js +18 -0
- package/lib/services/aws-parameters.js.map +1 -0
- package/lib/services/awscommands.service.d.ts +39 -0
- package/lib/services/awscommands.service.d.ts.map +1 -0
- package/lib/services/awscommands.service.js +127 -0
- package/lib/services/awscommands.service.js.map +1 -0
- package/lib/services/cloudwatchlogger.service.d.ts +131 -0
- package/lib/services/cloudwatchlogger.service.d.ts.map +1 -0
- package/lib/services/{cloudwatchlogger.js → cloudwatchlogger.service.js} +66 -34
- package/lib/services/cloudwatchlogger.service.js.map +1 -0
- package/lib/services/contributors.d.ts +37 -0
- package/lib/services/contributors.d.ts.map +1 -0
- package/lib/services/contributors.js +2 -0
- package/lib/services/contributors.js.map +1 -0
- package/lib/services/dynamodb.service.d.ts +297 -0
- package/lib/services/dynamodb.service.d.ts.map +1 -0
- package/lib/services/dynamodb.service.js +985 -0
- package/lib/services/dynamodb.service.js.map +1 -0
- package/lib/services/index.d.ts +12 -31
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +11 -8
- package/lib/services/index.js.map +1 -1
- package/lib/services/lambdacaller.service.d.ts +81 -0
- package/lib/services/lambdacaller.service.d.ts.map +1 -0
- package/lib/services/lambdacaller.service.js +75 -0
- package/lib/services/lambdacaller.service.js.map +1 -0
- package/lib/services/lambdaserver.service.d.ts +127 -0
- package/lib/services/lambdaserver.service.d.ts.map +1 -0
- package/lib/services/lambdaserver.service.js +294 -0
- package/lib/services/lambdaserver.service.js.map +1 -0
- package/lib/services/{route53.d.ts → route53.service.d.ts} +21 -11
- package/lib/services/route53.service.d.ts.map +1 -0
- package/lib/services/{route53.js → route53.service.js} +35 -38
- package/lib/services/route53.service.js.map +1 -0
- package/lib/services/s3binary.service.d.ts +215 -0
- package/lib/services/s3binary.service.d.ts.map +1 -0
- package/lib/services/{s3binary.js → s3binary.service.js} +113 -74
- package/lib/services/s3binary.service.js.map +1 -0
- package/lib/services/secretsmanager.service.d.ts +102 -0
- package/lib/services/secretsmanager.service.d.ts.map +1 -0
- package/lib/services/{secretsmanager.js → secretsmanager.service.js} +42 -24
- package/lib/services/secretsmanager.service.js.map +1 -0
- package/lib/services/{sqsqueue.d.ts → sqsqueue.service.d.ts} +60 -34
- package/lib/services/sqsqueue.service.d.ts.map +1 -0
- package/lib/services/{sqsqueue.js → sqsqueue.service.js} +60 -35
- package/lib/services/sqsqueue.service.js.map +1 -0
- package/package.json +59 -65
- package/webda.module.json +738 -377
- package/lib/deployers/cloudformation.d.ts +0 -316
- package/lib/deployers/cloudformation.js +0 -837
- package/lib/deployers/cloudformation.js.map +0 -1
- package/lib/deployers/cloudformation.spec.d.ts +0 -1
- package/lib/deployers/cloudformation.spec.js +0 -530
- package/lib/deployers/cloudformation.spec.js.map +0 -1
- package/lib/deployers/index.d.ts +0 -254
- package/lib/deployers/index.js +0 -543
- package/lib/deployers/index.js.map +0 -1
- package/lib/deployers/index.spec.d.ts +0 -8
- package/lib/deployers/index.spec.js +0 -595
- package/lib/deployers/index.spec.js.map +0 -1
- package/lib/deployers/lambda-entrypoint.d.ts +0 -1
- package/lib/deployers/lambda-entrypoint.js +0 -11
- package/lib/deployers/lambda-entrypoint.js.map +0 -1
- package/lib/deployers/lambdapackager.d.ts +0 -27
- package/lib/deployers/lambdapackager.js +0 -26
- package/lib/deployers/lambdapackager.js.map +0 -1
- package/lib/deployers/lambdapackager.spec.d.ts +0 -1
- package/lib/deployers/lambdapackager.spec.js +0 -44
- package/lib/deployers/lambdapackager.spec.js.map +0 -1
- package/lib/index.spec.d.ts +0 -10
- package/lib/index.spec.js +0 -42
- package/lib/index.spec.js.map +0 -1
- package/lib/services/aws-mixin.d.ts +0 -24
- package/lib/services/aws-mixin.js +0 -18
- package/lib/services/aws-mixin.js.map +0 -1
- package/lib/services/cloudwatchlogger.d.ts +0 -81
- package/lib/services/cloudwatchlogger.js.map +0 -1
- package/lib/services/cloudwatchlogger.spec.d.ts +0 -1
- package/lib/services/cloudwatchlogger.spec.js +0 -104
- package/lib/services/cloudwatchlogger.spec.js.map +0 -1
- package/lib/services/dynamodb.d.ts +0 -173
- package/lib/services/dynamodb.js +0 -711
- package/lib/services/dynamodb.js.map +0 -1
- package/lib/services/dynamodb.spec.d.ts +0 -23
- package/lib/services/dynamodb.spec.js +0 -339
- package/lib/services/dynamodb.spec.js.map +0 -1
- package/lib/services/lambdacaller.d.ts +0 -68
- package/lib/services/lambdacaller.js +0 -63
- package/lib/services/lambdacaller.js.map +0 -1
- package/lib/services/lambdacaller.spec.d.ts +0 -1
- package/lib/services/lambdacaller.spec.js +0 -70
- package/lib/services/lambdacaller.spec.js.map +0 -1
- package/lib/services/lambdaserver.d.ts +0 -86
- package/lib/services/lambdaserver.js +0 -264
- package/lib/services/lambdaserver.js.map +0 -1
- package/lib/services/lambdaserver.spec.d.ts +0 -1
- package/lib/services/lambdaserver.spec.js +0 -417
- package/lib/services/lambdaserver.spec.js.map +0 -1
- package/lib/services/route53.js.map +0 -1
- package/lib/services/route53.spec.d.ts +0 -1
- package/lib/services/route53.spec.js +0 -102
- package/lib/services/route53.spec.js.map +0 -1
- package/lib/services/s3binary.d.ts +0 -162
- package/lib/services/s3binary.js.map +0 -1
- package/lib/services/s3binary.spec.d.ts +0 -1
- package/lib/services/s3binary.spec.js +0 -269
- package/lib/services/s3binary.spec.js.map +0 -1
- package/lib/services/secretsmanager.d.ts +0 -80
- package/lib/services/secretsmanager.js.map +0 -1
- package/lib/services/secretsmanager.spec.d.ts +0 -1
- package/lib/services/secretsmanager.spec.js +0 -66
- package/lib/services/secretsmanager.spec.js.map +0 -1
- package/lib/services/sqsqueue.js.map +0 -1
- package/lib/services/sqsqueue.spec.d.ts +0 -1
- package/lib/services/sqsqueue.spec.js +0 -152
- package/lib/services/sqsqueue.spec.js.map +0 -1
- package/lib/shell.d.ts +0 -12
- package/lib/shell.js +0 -42
- package/lib/shell.js.map +0 -1
- package/webda.shell.json +0 -11
package/README.md
CHANGED
|
@@ -13,13 +13,70 @@ This module is part of Webda Application Framework that allows you to quickly de
|
|
|
13
13
|
|
|
14
14
|
<!-- README_HEADER -->
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
|
|
22
|
-
You
|
|
16
|
+
# @webda/aws
|
|
17
|
+
|
|
18
|
+
> AWS integration bundle for Webda — DynamoDB Store, S3 Binary, SQS Queue, CloudWatch Logger, Secrets Manager, Lambda server, Route53, and Lambda/CloudFormation deployers in one package.
|
|
19
|
+
|
|
20
|
+
## When to use it
|
|
21
|
+
|
|
22
|
+
- You are deploying a Webda application on AWS (Lambda or EC2/ECS) and need cloud-native backing services.
|
|
23
|
+
- You want to swap out `MemoryStore` / `MemoryQueue` / `FileBinary` with AWS-managed equivalents for production.
|
|
24
|
+
- You need to deploy your application as a Lambda function or manage infrastructure via CloudFormation.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @webda/aws
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## What's inside
|
|
33
|
+
|
|
34
|
+
### Runtime services
|
|
35
|
+
|
|
36
|
+
- `DynamoStore` — DynamoDB-backed Store for any Webda model ([source](./src/services/dynamodb.ts))
|
|
37
|
+
- `S3Binary` — S3-backed Binary service for file uploads and downloads ([source](./src/services/s3binary.ts))
|
|
38
|
+
- `SQSQueue` — SQS-backed Queue for durable task queuing ([source](./src/services/sqsqueue.ts))
|
|
39
|
+
- `CloudWatchLogger` — Streams application logs to CloudWatch Logs ([source](./src/services/cloudwatchlogger.ts))
|
|
40
|
+
- `SecretsManager` — Resolves configuration parameters from AWS Secrets Manager ([source](./src/services/secretsmanager.ts))
|
|
41
|
+
- `Route53` — DNS record management via Route53 ([source](./src/services/route53.ts))
|
|
42
|
+
- `LambdaServer` — Adapts incoming Lambda events to Webda's HTTP context ([source](./src/services/lambdaserver.ts))
|
|
43
|
+
- `LambdaCaller` — Invokes other Lambda functions as service calls ([source](./src/services/lambdacaller.ts))
|
|
44
|
+
|
|
45
|
+
### Deployers (shell/build-time)
|
|
46
|
+
|
|
47
|
+
- `LambdaDeployer` — Packages and deploys the application as an AWS Lambda function ([source](./src/deployers/lambda-entrypoint.ts))
|
|
48
|
+
- `CloudFormationDeployer` — Full infrastructure deployment via AWS CloudFormation ([source](./src/deployers/cloudformation.ts))
|
|
49
|
+
- `LambdaPackager` — Bundles the application for Lambda deployment ([source](./src/deployers/lambdapackager.ts))
|
|
50
|
+
|
|
51
|
+
## Quick config example
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"services": {
|
|
56
|
+
"userStore": {
|
|
57
|
+
"type": "DynamoStore",
|
|
58
|
+
"model": "MyApp/User",
|
|
59
|
+
"table": "my-app-users",
|
|
60
|
+
"region": "us-east-1"
|
|
61
|
+
},
|
|
62
|
+
"uploadBucket": {
|
|
63
|
+
"type": "S3Binary",
|
|
64
|
+
"bucket": "my-app-uploads",
|
|
65
|
+
"region": "us-east-1"
|
|
66
|
+
},
|
|
67
|
+
"taskQueue": {
|
|
68
|
+
"type": "SQSQueue",
|
|
69
|
+
"queue": "https://sqs.us-east-1.amazonaws.com/123456789/my-tasks"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Reference
|
|
76
|
+
|
|
77
|
+
- API reference: see the auto-generated typedoc at `docs/pages/Modules/aws/`.
|
|
78
|
+
- Source: [`packages/aws`](https://github.com/loopingz/webda.io/tree/main/packages/aws)
|
|
79
|
+
- Related: [`@webda/core`](../core) for Store, Queue, and Binary base classes; [`@webda/async`](../async) for job orchestration using SQSQueue.
|
|
23
80
|
|
|
24
81
|
<!-- README_FOOTER -->
|
|
25
82
|
## Sponsors
|
package/lib/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS client parameters shared by the AWS services
|
|
3
|
+
*
|
|
4
|
+
* Each service parameters class declares these fields and calls
|
|
5
|
+
* {@link loadAWSParameters} from its `load()` override
|
|
6
|
+
*/
|
|
7
|
+
export interface AWSServiceParameters {
|
|
8
|
+
/**
|
|
9
|
+
* Custom endpoint (localstack, minio, ...)
|
|
10
|
+
*/
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Static credentials, default to the AWS environment variables
|
|
14
|
+
*/
|
|
15
|
+
credentials?: {
|
|
16
|
+
accessKeyId: string;
|
|
17
|
+
secretAccessKey: string;
|
|
18
|
+
sessionToken?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* AWS region
|
|
22
|
+
* @default "us-east-1"
|
|
23
|
+
*/
|
|
24
|
+
region?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Default the region and credentials from the AWS environment variables
|
|
28
|
+
*
|
|
29
|
+
* @param params - the parameters to complete
|
|
30
|
+
* @returns the parameters
|
|
31
|
+
*/
|
|
32
|
+
export declare function loadAWSParameters<T extends AWSServiceParameters>(params: T): T;
|
|
33
|
+
//# sourceMappingURL=aws-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-parameters.d.ts","sourceRoot":"","sources":["../../src/services/aws-parameters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,oBAAoB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAU9E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default the region and credentials from the AWS environment variables
|
|
3
|
+
*
|
|
4
|
+
* @param params - the parameters to complete
|
|
5
|
+
* @returns the parameters
|
|
6
|
+
*/
|
|
7
|
+
export function loadAWSParameters(params) {
|
|
8
|
+
params.region ?? (params.region = process.env["AWS_DEFAULT_REGION"] || "us-east-1");
|
|
9
|
+
if (process.env["AWS_ACCESS_KEY_ID"] && process.env["AWS_SECRET_ACCESS_KEY"] && !process.env["ECS_CLUSTER"]) {
|
|
10
|
+
params.credentials ?? (params.credentials = {
|
|
11
|
+
accessKeyId: process.env["AWS_ACCESS_KEY_ID"],
|
|
12
|
+
secretAccessKey: process.env["AWS_SECRET_ACCESS_KEY"],
|
|
13
|
+
sessionToken: process.env["AWS_SESSION_TOKEN"]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return params;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=aws-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-parameters.js","sourceRoot":"","sources":["../../src/services/aws-parameters.ts"],"names":[],"mappings":"AA0BA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAiC,MAAS;IACzE,MAAM,CAAC,MAAM,KAAb,MAAM,CAAC,MAAM,GAAK,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,WAAW,EAAC;IACnE,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC5G,MAAM,CAAC,WAAW,KAAlB,MAAM,CAAC,WAAW,GAAK;YACrB,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;YAC7C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;YACrD,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;SAC/C,EAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Service } from "@webda/core";
|
|
2
|
+
/**
|
|
3
|
+
* AWS command line utilities
|
|
4
|
+
*
|
|
5
|
+
* Exposes the `webda aws route53 export|import|sync` and `webda aws copyTable` commands
|
|
6
|
+
*
|
|
7
|
+
* @WebdaModda
|
|
8
|
+
*/
|
|
9
|
+
export declare class AWSCommands extends Service {
|
|
10
|
+
/**
|
|
11
|
+
* Export a Route53 domain to a file
|
|
12
|
+
*
|
|
13
|
+
* @param domain - the domain to export
|
|
14
|
+
* @param file - the file to export to (.json or .yml)
|
|
15
|
+
*/
|
|
16
|
+
route53Export(domain: string, file: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Import a Route53 exported file to Route53
|
|
19
|
+
*
|
|
20
|
+
* @param file - the exported file
|
|
21
|
+
*/
|
|
22
|
+
route53Import(file: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Sync a Route53 exported file to Route53, removing any other entries
|
|
25
|
+
*
|
|
26
|
+
* @param file - the exported file
|
|
27
|
+
* @param pretend - only display the entries that would be removed
|
|
28
|
+
*/
|
|
29
|
+
route53Sync(file: string, pretend?: boolean): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Copy all items of a DynamoDB table into another one
|
|
32
|
+
*
|
|
33
|
+
* @param sourceTable - the table to copy from
|
|
34
|
+
* @param targetTable - the table to copy to
|
|
35
|
+
*/
|
|
36
|
+
copyTable(sourceTable: string, targetTable: string): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export default AWSCommands;
|
|
39
|
+
//# sourceMappingURL=awscommands.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"awscommands.service.d.ts","sourceRoot":"","sources":["../../src/services/awscommands.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,OAAO,EAAE,MAAM,aAAa,CAAC;AAK/C;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,OAAO;IACtC;;;;;OAKG;IAMG,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/D;IAED;;;;OAIG;IAMG,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;IAED;;;;;OAKG;IAMG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvE;IAED;;;;;OAKG;IAMG,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvE;CACF;eAEc,WAAW"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { Command, Service } from "@webda/core";
|
|
36
|
+
import { useWorkerOutput } from "@webda/workout";
|
|
37
|
+
import { DynamoStore } from "./dynamodb.service.js";
|
|
38
|
+
import { Route53Service } from "./route53.service.js";
|
|
39
|
+
/**
|
|
40
|
+
* AWS command line utilities
|
|
41
|
+
*
|
|
42
|
+
* Exposes the `webda aws route53 export|import|sync` and `webda aws copyTable` commands
|
|
43
|
+
*
|
|
44
|
+
* @WebdaModda
|
|
45
|
+
*/
|
|
46
|
+
let AWSCommands = (() => {
|
|
47
|
+
var _a;
|
|
48
|
+
let _classSuper = Service;
|
|
49
|
+
let _instanceExtraInitializers = [];
|
|
50
|
+
let _route53Export_decorators;
|
|
51
|
+
let _route53Import_decorators;
|
|
52
|
+
let _route53Sync_decorators;
|
|
53
|
+
let _copyTable_decorators;
|
|
54
|
+
return _a = class AWSCommands extends _classSuper {
|
|
55
|
+
/**
|
|
56
|
+
* Export a Route53 domain to a file
|
|
57
|
+
*
|
|
58
|
+
* @param domain - the domain to export
|
|
59
|
+
* @param file - the file to export to (.json or .yml)
|
|
60
|
+
*/
|
|
61
|
+
async route53Export(domain, file) {
|
|
62
|
+
await Route53Service.export(domain, file);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Import a Route53 exported file to Route53
|
|
66
|
+
*
|
|
67
|
+
* @param file - the exported file
|
|
68
|
+
*/
|
|
69
|
+
async route53Import(file) {
|
|
70
|
+
await Route53Service.import({ file }, this.log.bind(this));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Sync a Route53 exported file to Route53, removing any other entries
|
|
74
|
+
*
|
|
75
|
+
* @param file - the exported file
|
|
76
|
+
* @param pretend - only display the entries that would be removed
|
|
77
|
+
*/
|
|
78
|
+
async route53Sync(file, pretend = false) {
|
|
79
|
+
await Route53Service.import({ file, pretend, sync: true }, this.log.bind(this));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Copy all items of a DynamoDB table into another one
|
|
83
|
+
*
|
|
84
|
+
* @param sourceTable - the table to copy from
|
|
85
|
+
* @param targetTable - the table to copy to
|
|
86
|
+
*/
|
|
87
|
+
async copyTable(sourceTable, targetTable) {
|
|
88
|
+
await DynamoStore.copyTable(useWorkerOutput(), sourceTable, targetTable);
|
|
89
|
+
}
|
|
90
|
+
constructor() {
|
|
91
|
+
super(...arguments);
|
|
92
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
(() => {
|
|
96
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
97
|
+
_route53Export_decorators = [Command("aws route53 export", {
|
|
98
|
+
description: "Export a Route53 domain to a json file",
|
|
99
|
+
requires: ["aws-commands"],
|
|
100
|
+
phase: "resolved"
|
|
101
|
+
})];
|
|
102
|
+
_route53Import_decorators = [Command("aws route53 import", {
|
|
103
|
+
description: "Import a Route53 exported format to Route53",
|
|
104
|
+
requires: ["aws-commands"],
|
|
105
|
+
phase: "resolved"
|
|
106
|
+
})];
|
|
107
|
+
_route53Sync_decorators = [Command("aws route53 sync", {
|
|
108
|
+
description: "Sync a Route53 exported format to Route53 (remove all others entries)",
|
|
109
|
+
requires: ["aws-commands"],
|
|
110
|
+
phase: "resolved"
|
|
111
|
+
})];
|
|
112
|
+
_copyTable_decorators = [Command("aws copyTable", {
|
|
113
|
+
description: "Copy a DynamoDB table content to another table",
|
|
114
|
+
requires: ["aws-commands"],
|
|
115
|
+
phase: "resolved"
|
|
116
|
+
})];
|
|
117
|
+
__esDecorate(_a, null, _route53Export_decorators, { kind: "method", name: "route53Export", static: false, private: false, access: { has: obj => "route53Export" in obj, get: obj => obj.route53Export }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
118
|
+
__esDecorate(_a, null, _route53Import_decorators, { kind: "method", name: "route53Import", static: false, private: false, access: { has: obj => "route53Import" in obj, get: obj => obj.route53Import }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
119
|
+
__esDecorate(_a, null, _route53Sync_decorators, { kind: "method", name: "route53Sync", static: false, private: false, access: { has: obj => "route53Sync" in obj, get: obj => obj.route53Sync }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
120
|
+
__esDecorate(_a, null, _copyTable_decorators, { kind: "method", name: "copyTable", static: false, private: false, access: { has: obj => "copyTable" in obj, get: obj => obj.copyTable }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
121
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
122
|
+
})(),
|
|
123
|
+
_a;
|
|
124
|
+
})();
|
|
125
|
+
export { AWSCommands };
|
|
126
|
+
export default AWSCommands;
|
|
127
|
+
//# sourceMappingURL=awscommands.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"awscommands.service.js","sourceRoot":"","sources":["../../src/services/awscommands.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;GAMG;IACU,WAAW;;sBAAS,OAAO;;;;;;sBAA3B,WAAY,SAAQ,WAAO;YACtC;;;;;eAKG;YAMH,KAAK,CAAC,aAAa,CAAC,MAAc,EAAE,IAAY;gBAC9C,MAAM,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC5C,CAAC;YAED;;;;eAIG;YAMH,KAAK,CAAC,aAAa,CAAC,IAAY;gBAC9B,MAAM,cAAc,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7D,CAAC;YAED;;;;;eAKG;YAMH,KAAK,CAAC,WAAW,CAAC,IAAY,EAAE,OAAO,GAAY,KAAK;gBACtD,MAAM,cAAc,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAClF,CAAC;YAED;;;;;eAKG;YAMH,KAAK,CAAC,SAAS,CAAC,WAAmB,EAAE,WAAmB;gBACtD,MAAM,WAAW,CAAC,SAAS,CAAC,eAAe,EAAE,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;YAC3E,CAAC;;;gBA1DU,mDAAW;;;;;yCAOrB,OAAO,CAAC,oBAAoB,EAAE;oBAC7B,WAAW,EAAE,wCAAwC;oBACrD,QAAQ,EAAE,CAAC,cAAc,CAAC;oBAC1B,KAAK,EAAE,UAAU;iBAClB,CAAC;yCAUD,OAAO,CAAC,oBAAoB,EAAE;oBAC7B,WAAW,EAAE,6CAA6C;oBAC1D,QAAQ,EAAE,CAAC,cAAc,CAAC;oBAC1B,KAAK,EAAE,UAAU;iBAClB,CAAC;uCAWD,OAAO,CAAC,kBAAkB,EAAE;oBAC3B,WAAW,EAAE,uEAAuE;oBACpF,QAAQ,EAAE,CAAC,cAAc,CAAC;oBAC1B,KAAK,EAAE,UAAU;iBAClB,CAAC;qCAWD,OAAO,CAAC,eAAe,EAAE;oBACxB,WAAW,EAAE,gDAAgD;oBAC7D,QAAQ,EAAE,CAAC,cAAc,CAAC;oBAC1B,KAAK,EAAE,UAAU;iBAClB,CAAC;YA3CF,wLAAM,aAAa,6DAElB;YAYD,wLAAM,aAAa,6DAElB;YAaD,kLAAM,WAAW,6DAEhB;YAaD,4KAAM,SAAS,6DAEd;;;;;SA1DU,WAAW;AA6DxB,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
|
|
2
|
+
import { Service, ServiceParameters } from "@webda/core";
|
|
3
|
+
import { WorkerLogLevel, WorkerMessage } from "@webda/workout";
|
|
4
|
+
import { AWSServiceParameters } from "./aws-parameters.js";
|
|
5
|
+
import type { CloudFormationContributor } from "./contributors.js";
|
|
6
|
+
/**
|
|
7
|
+
* Send webda log to CloudWatch
|
|
8
|
+
*/
|
|
9
|
+
export declare class CloudWatchLoggerParameters extends ServiceParameters implements AWSServiceParameters {
|
|
10
|
+
/**
|
|
11
|
+
* Custom endpoint (localstack, minio, ...)
|
|
12
|
+
*/
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Static credentials, default to the AWS environment variables
|
|
16
|
+
*/
|
|
17
|
+
credentials?: {
|
|
18
|
+
accessKeyId: string;
|
|
19
|
+
secretAccessKey: string;
|
|
20
|
+
sessionToken?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* AWS region
|
|
24
|
+
* @default "us-east-1"
|
|
25
|
+
*/
|
|
26
|
+
region?: string;
|
|
27
|
+
/**
|
|
28
|
+
* logGroupName to send logStream to
|
|
29
|
+
*/
|
|
30
|
+
logGroupName: string;
|
|
31
|
+
/**
|
|
32
|
+
* Prefix of the log stream name, a random uuid is appended
|
|
33
|
+
*/
|
|
34
|
+
logStreamNamePrefix?: string;
|
|
35
|
+
/**
|
|
36
|
+
* KMS key to use when creating the log group
|
|
37
|
+
*/
|
|
38
|
+
kmsKeyId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Tags to add when creating the log group
|
|
41
|
+
*/
|
|
42
|
+
tags?: any;
|
|
43
|
+
/**
|
|
44
|
+
* Minimum level of logs to send
|
|
45
|
+
* @default "INFO"
|
|
46
|
+
*/
|
|
47
|
+
logLevel?: WorkerLogLevel;
|
|
48
|
+
/**
|
|
49
|
+
* Send each log line as soon as it is produced
|
|
50
|
+
*/
|
|
51
|
+
singlePush?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* CloudFormation customization
|
|
54
|
+
*/
|
|
55
|
+
CloudFormation?: any;
|
|
56
|
+
/**
|
|
57
|
+
* Skip CloudFormation on deploy
|
|
58
|
+
*/
|
|
59
|
+
CloudFormationSkip?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* @override
|
|
62
|
+
* @param params - raw parameters
|
|
63
|
+
* @returns this
|
|
64
|
+
*/
|
|
65
|
+
load(params?: any): this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Output log to a CloudWatch Stream
|
|
69
|
+
*
|
|
70
|
+
* @WebdaModda
|
|
71
|
+
*/
|
|
72
|
+
export declare class CloudWatchLogger<T extends CloudWatchLoggerParameters = CloudWatchLoggerParameters> extends Service<T> implements CloudFormationContributor {
|
|
73
|
+
_logGroupName: string;
|
|
74
|
+
_logStreamName: string;
|
|
75
|
+
_seqToken: string;
|
|
76
|
+
_logStream: any;
|
|
77
|
+
_cloudwatch: CloudWatchLogs;
|
|
78
|
+
_bufferedLogs: any[];
|
|
79
|
+
/**
|
|
80
|
+
* Listener on the worker output
|
|
81
|
+
*/
|
|
82
|
+
protected messageListener: (msg: WorkerMessage) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Unsubscribe from the Webda.Result core event
|
|
85
|
+
*/
|
|
86
|
+
protected resultListenerOff: () => void;
|
|
87
|
+
/**
|
|
88
|
+
* Create the log group and stream, then forward the logs
|
|
89
|
+
* @returns this
|
|
90
|
+
*/
|
|
91
|
+
init(): Promise<this>;
|
|
92
|
+
/**
|
|
93
|
+
* Remove the log and result listeners
|
|
94
|
+
*/
|
|
95
|
+
protected removeListeners(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Flush the logs and stop forwarding
|
|
98
|
+
* @override
|
|
99
|
+
*/
|
|
100
|
+
stop(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Send logs to CloudWatch
|
|
103
|
+
*
|
|
104
|
+
* @param copy - send a copy of the buffer and reset it before sending
|
|
105
|
+
*/
|
|
106
|
+
sendLogs(copy?: boolean): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Buffer a log line
|
|
109
|
+
* @param level - log level
|
|
110
|
+
* @param args - log arguments
|
|
111
|
+
*/
|
|
112
|
+
_log(level: WorkerLogLevel, ...args: any[]): void;
|
|
113
|
+
/**
|
|
114
|
+
* IAM policy required by the service
|
|
115
|
+
* @param accountId - AWS account id
|
|
116
|
+
* @returns the policy statement
|
|
117
|
+
*/
|
|
118
|
+
getARNPolicy(accountId: string): {
|
|
119
|
+
Sid: string;
|
|
120
|
+
Effect: string;
|
|
121
|
+
Action: string[];
|
|
122
|
+
Resource: string[];
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* CloudFormation resources for the log group
|
|
126
|
+
* @returns the resources
|
|
127
|
+
*/
|
|
128
|
+
getCloudFormation(): {};
|
|
129
|
+
}
|
|
130
|
+
export default CloudWatchLogger;
|
|
131
|
+
//# sourceMappingURL=cloudwatchlogger.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudwatchlogger.service.d.ts","sourceRoot":"","sources":["../../src/services/cloudwatchlogger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAiB,MAAM,aAAa,CAAC;AACxE,OAAO,EAA8B,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3F,OAAO,EAAE,oBAAoB,EAAqB,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,iBAAkB,YAAW,oBAAoB;IAC/F;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtF;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;IACX;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;OAIG;IACH,IAAI,CAAC,MAAM,GAAE,GAAQ,GAAG,IAAI,CAK3B;CACF;AAED;;;;GAIG;AACH,qBAAa,gBAAgB,CAAC,CAAC,SAAS,0BAA0B,GAAG,0BAA0B,CAC7F,SAAQ,OAAO,CAAC,CAAC,CACjB,YAAW,yBAAyB;IAEpC,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,cAAc,CAAC;IAC5B,aAAa,EAAE,GAAG,EAAE,CAAM;IAC1B;;OAEG;IACH,SAAS,CAAC,eAAe,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;IACxD;;OAEG;IACH,SAAS,CAAC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAExC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAkC1B;IAED;;OAEG;IACH,SAAS,CAAC,eAAe,SAOxB;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAI1B;IAED;;;;OAIG;IACG,QAAQ,CAAC,IAAI,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBnD;IAED;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAUhD;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM;QAG1B,GAAG;QACH,MAAM;QACN,MAAM;QACN,QAAQ;MAKX;IAED;;;OAGG;IACH,iBAAiB,OAehB;CACF;eAEc,gBAAgB"}
|
|
@@ -1,33 +1,37 @@
|
|
|
1
1
|
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
|
|
2
|
-
import { Service, ServiceParameters } from "@webda/core";
|
|
3
|
-
import { LogFilter } from "@webda/workout";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
2
|
+
import { Service, ServiceParameters, useCoreEvents } from "@webda/core";
|
|
3
|
+
import { LogFilter, useWorkerOutput } from "@webda/workout";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { loadAWSParameters } from "./aws-parameters.js";
|
|
6
6
|
/**
|
|
7
7
|
* Send webda log to CloudWatch
|
|
8
8
|
*/
|
|
9
|
-
export class CloudWatchLoggerParameters extends
|
|
9
|
+
export class CloudWatchLoggerParameters extends ServiceParameters {
|
|
10
|
+
/**
|
|
11
|
+
* @override
|
|
12
|
+
* @param params - raw parameters
|
|
13
|
+
* @returns this
|
|
14
|
+
*/
|
|
15
|
+
load(params = {}) {
|
|
16
|
+
super.load(params);
|
|
17
|
+
loadAWSParameters(this);
|
|
18
|
+
this.logLevel ?? (this.logLevel = "INFO");
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
10
21
|
}
|
|
11
22
|
/**
|
|
12
23
|
* Output log to a CloudWatch Stream
|
|
13
24
|
*
|
|
14
25
|
* @WebdaModda
|
|
15
26
|
*/
|
|
16
|
-
export
|
|
27
|
+
export class CloudWatchLogger extends Service {
|
|
17
28
|
constructor() {
|
|
18
29
|
super(...arguments);
|
|
19
30
|
this._bufferedLogs = [];
|
|
20
31
|
}
|
|
21
32
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @param params
|
|
25
|
-
*/
|
|
26
|
-
loadParameters(params) {
|
|
27
|
-
return new CloudWatchLoggerParameters(params);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @inheritdoc
|
|
33
|
+
* Create the log group and stream, then forward the logs
|
|
34
|
+
* @returns this
|
|
31
35
|
*/
|
|
32
36
|
async init() {
|
|
33
37
|
await super.init();
|
|
@@ -35,9 +39,9 @@ export default class CloudWatchLogger extends Service {
|
|
|
35
39
|
if (!this._logGroupName) {
|
|
36
40
|
throw Error("Require a log group `logGroupName` parameter");
|
|
37
41
|
}
|
|
38
|
-
this._logStreamName = (this.parameters.logStreamNamePrefix || "") +
|
|
42
|
+
this._logStreamName = (this.parameters.logStreamNamePrefix || "") + randomUUID();
|
|
39
43
|
this._cloudwatch = new CloudWatchLogs(this.parameters);
|
|
40
|
-
|
|
44
|
+
const res = await this._cloudwatch.describeLogGroups({
|
|
41
45
|
logGroupNamePrefix: this._logGroupName
|
|
42
46
|
});
|
|
43
47
|
if (!res.logGroups.length) {
|
|
@@ -51,22 +55,43 @@ export default class CloudWatchLogger extends Service {
|
|
|
51
55
|
logGroupName: this._logGroupName,
|
|
52
56
|
logStreamName: this._logStreamName
|
|
53
57
|
});
|
|
54
|
-
this.
|
|
58
|
+
this.removeListeners();
|
|
59
|
+
this.messageListener = (msg) => {
|
|
55
60
|
if (msg.type !== "log") {
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
58
63
|
if (LogFilter(msg.log.level, this.parameters.logLevel)) {
|
|
59
64
|
this._log(msg.log.level, ...msg.log.args);
|
|
60
65
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
66
|
+
};
|
|
67
|
+
useWorkerOutput().on("message", this.messageListener);
|
|
68
|
+
this.resultListenerOff = useCoreEvents("Webda.Result", () => this.sendLogs());
|
|
63
69
|
return this;
|
|
64
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Remove the log and result listeners
|
|
73
|
+
*/
|
|
74
|
+
removeListeners() {
|
|
75
|
+
if (this.messageListener) {
|
|
76
|
+
useWorkerOutput().off("message", this.messageListener);
|
|
77
|
+
this.messageListener = undefined;
|
|
78
|
+
}
|
|
79
|
+
this.resultListenerOff?.();
|
|
80
|
+
this.resultListenerOff = undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Flush the logs and stop forwarding
|
|
84
|
+
* @override
|
|
85
|
+
*/
|
|
86
|
+
async stop() {
|
|
87
|
+
this.removeListeners();
|
|
88
|
+
await this.sendLogs();
|
|
89
|
+
await super.stop();
|
|
90
|
+
}
|
|
65
91
|
/**
|
|
66
92
|
* Send logs to CloudWatch
|
|
67
93
|
*
|
|
68
|
-
* @param copy
|
|
69
|
-
* @returns
|
|
94
|
+
* @param copy - send a copy of the buffer and reset it before sending
|
|
70
95
|
*/
|
|
71
96
|
async sendLogs(copy = false) {
|
|
72
97
|
if (!this._bufferedLogs.length) {
|
|
@@ -80,20 +105,22 @@ export default class CloudWatchLogger extends Service {
|
|
|
80
105
|
else {
|
|
81
106
|
toSend = this._bufferedLogs;
|
|
82
107
|
}
|
|
83
|
-
|
|
108
|
+
const params = {
|
|
84
109
|
logEvents: toSend,
|
|
85
110
|
logGroupName: this._logGroupName,
|
|
86
111
|
logStreamName: this._logStreamName,
|
|
87
112
|
sequenceToken: this._seqToken
|
|
88
113
|
};
|
|
89
|
-
|
|
114
|
+
const res = await this._cloudwatch.putLogEvents(params);
|
|
90
115
|
this._seqToken = res.nextSequenceToken;
|
|
91
116
|
if (!copy) {
|
|
92
117
|
this._bufferedLogs = [];
|
|
93
118
|
}
|
|
94
119
|
}
|
|
95
120
|
/**
|
|
96
|
-
*
|
|
121
|
+
* Buffer a log line
|
|
122
|
+
* @param level - log level
|
|
123
|
+
* @param args - log arguments
|
|
97
124
|
*/
|
|
98
125
|
_log(level, ...args) {
|
|
99
126
|
this._bufferedLogs.push({
|
|
@@ -101,16 +128,20 @@ export default class CloudWatchLogger extends Service {
|
|
|
101
128
|
timestamp: new Date().getTime()
|
|
102
129
|
});
|
|
103
130
|
if (this.parameters.singlePush) {
|
|
104
|
-
this.sendLogs(true)
|
|
131
|
+
this.sendLogs(true).catch(() => {
|
|
132
|
+
// Ignore send errors to avoid logging loops
|
|
133
|
+
});
|
|
105
134
|
}
|
|
106
135
|
}
|
|
107
136
|
/**
|
|
108
|
-
*
|
|
137
|
+
* IAM policy required by the service
|
|
138
|
+
* @param accountId - AWS account id
|
|
139
|
+
* @returns the policy statement
|
|
109
140
|
*/
|
|
110
141
|
getARNPolicy(accountId) {
|
|
111
|
-
|
|
142
|
+
const region = this.parameters.region || "us-east-1";
|
|
112
143
|
return {
|
|
113
|
-
Sid: this.constructor.name + this.
|
|
144
|
+
Sid: this.constructor.name + this.getName(),
|
|
114
145
|
Effect: "Allow",
|
|
115
146
|
Action: ["logs:*"],
|
|
116
147
|
Resource: [
|
|
@@ -120,15 +151,16 @@ export default class CloudWatchLogger extends Service {
|
|
|
120
151
|
};
|
|
121
152
|
}
|
|
122
153
|
/**
|
|
123
|
-
*
|
|
154
|
+
* CloudFormation resources for the log group
|
|
155
|
+
* @returns the resources
|
|
124
156
|
*/
|
|
125
157
|
getCloudFormation() {
|
|
126
158
|
if (this.parameters.CloudFormationSkip) {
|
|
127
159
|
return {};
|
|
128
160
|
}
|
|
129
|
-
|
|
161
|
+
const resources = {};
|
|
130
162
|
this.parameters.CloudFormation = this.parameters.CloudFormation || {};
|
|
131
|
-
resources[this.
|
|
163
|
+
resources[this.getName() + "LogGroup"] = {
|
|
132
164
|
Type: "AWS::Logs::LogGroup",
|
|
133
165
|
Properties: {
|
|
134
166
|
...this.parameters.CloudFormation.LogGroup,
|
|
@@ -139,5 +171,5 @@ export default class CloudWatchLogger extends Service {
|
|
|
139
171
|
return resources;
|
|
140
172
|
}
|
|
141
173
|
}
|
|
142
|
-
export
|
|
143
|
-
//# sourceMappingURL=cloudwatchlogger.js.map
|
|
174
|
+
export default CloudWatchLogger;
|
|
175
|
+
//# sourceMappingURL=cloudwatchlogger.service.js.map
|