@comicrelief/lambda-wrapper 1.8.2 → 1.10.0
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Lambda Wrapper
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
[](https://github.com/semantic-release/semantic-release)
|
|
5
5
|
[](https://www.npmjs.com/package/@comicrelief/lambda-wrapper)
|
|
6
6
|
|
|
@@ -82,10 +82,16 @@ The URL is likely to be your localhost URL and the next available port from the
|
|
|
82
82
|
Use this mode by setting `LAMBDA_WRAPPER_OFFLINE_SQS_MODE=local`. Messages will still be sent to an SQS queue, but using a locally simulated version instead of AWS. This allows you to test your service using a tool like Localstack.
|
|
83
83
|
|
|
84
84
|
By default, messages will be sent to a SQS service running on `localhost:4576`. If you need to change the hostname, you can set `process.env.LAMBDA_WRAPPER_OFFLINE_SQS_HOST`.
|
|
85
|
+
Also, if you need to change the port, you can set `process.env.LAMBDA_WRAPPER_OFFLINE_SQS_PORT`.
|
|
85
86
|
|
|
86
87
|
### AWS SQS mode
|
|
87
88
|
|
|
88
|
-
Use this mode by setting `LAMBDA_WRAPPER_OFFLINE_SQS_MODE=aws`. Messages will be sent to the real queue in AWS. This is useful
|
|
89
|
+
Use this mode by setting `LAMBDA_WRAPPER_OFFLINE_SQS_MODE=aws`. Messages will be sent to the real queue in AWS. This mode is useful when a queue is consumed by an external service, rather than another function in the service under test.
|
|
90
|
+
|
|
91
|
+
In order for queue URLs to be correctly constructed, you must either:
|
|
92
|
+
|
|
93
|
+
- set `AWS_ACCOUNT_ID` to the account ID that hosts your queue; or
|
|
94
|
+
- invoke offline functions via the Lambda API, passing a context that contains a realistic `invokedFunctionArn` including the account ID.
|
|
89
95
|
|
|
90
96
|
## Semantic release
|
|
91
97
|
|
|
@@ -245,7 +245,7 @@ class LoggerService extends _DependencyAware.default {
|
|
|
245
245
|
|
|
246
246
|
label(descriptor, silent = false) {
|
|
247
247
|
if (typeof process.env.EPSAGON_TOKEN === 'string' && process.env.EPSAGON_TOKEN !== 'undefined' && typeof process.env.EPSAGON_SERVICE_NAME === 'string' && process.env.EPSAGON_SERVICE_NAME !== 'undefined') {
|
|
248
|
-
_epsagon.default.label(descriptor);
|
|
248
|
+
_epsagon.default.label(descriptor, true);
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
if (silent === false) {
|
|
@@ -87,17 +87,20 @@ class SQSService extends _DependencyAware.default {
|
|
|
87
87
|
*/
|
|
88
88
|
constructor(di) {
|
|
89
89
|
super(di);
|
|
90
|
+
const {
|
|
91
|
+
LAMBDA_WRAPPER_OFFLINE_SQS_HOST: offlineHost = 'localhost',
|
|
92
|
+
LAMBDA_WRAPPER_OFFLINE_SQS_PORT: offlinePort = '4576',
|
|
93
|
+
LAMBDA_WRAPPER_OFFLINE_SQS_MODE: offlineMode = SQS_OFFLINE_MODES.DIRECT,
|
|
94
|
+
AWS_ACCOUNT_ID,
|
|
95
|
+
REGION
|
|
96
|
+
} = process.env;
|
|
90
97
|
const container = this.getContainer();
|
|
91
98
|
const context = container.getContext();
|
|
92
99
|
const queues = container.getConfiguration('QUEUES');
|
|
100
|
+
const accountId = context && context.invokedFunctionArn && _alai.default.parse(context) || AWS_ACCOUNT_ID;
|
|
93
101
|
this.queues = {};
|
|
94
102
|
this.$lambda = null;
|
|
95
103
|
this.$sqs = null;
|
|
96
|
-
const {
|
|
97
|
-
LAMBDA_WRAPPER_OFFLINE_SQS_HOST: offlineHost = 'localhost',
|
|
98
|
-
LAMBDA_WRAPPER_OFFLINE_SQS_MODE: offlineMode = SQS_OFFLINE_MODES.DIRECT,
|
|
99
|
-
REGION
|
|
100
|
-
} = process.env;
|
|
101
104
|
|
|
102
105
|
if (container.isOffline && !Object.values(SQS_OFFLINE_MODES).includes(offlineMode)) {
|
|
103
106
|
throw new Error(`Invalid LAMBDA_WRAPPER_OFFLINE_SQS_MODE: ${offlineMode}\n` + `Please use one of: ${Object.values(SQS_OFFLINE_MODES).join(', ')}`);
|
|
@@ -108,10 +111,10 @@ class SQSService extends _DependencyAware.default {
|
|
|
108
111
|
Object.keys(queues).forEach(queueDefinition => {
|
|
109
112
|
if (container.isOffline && offlineMode === SQS_OFFLINE_MODES.LOCAL) {
|
|
110
113
|
// custom URL when using an offline SQS service such as Localstack
|
|
111
|
-
this.queues[queueDefinition] = `http://${offlineHost}
|
|
114
|
+
this.queues[queueDefinition] = `http://${offlineHost}:${offlinePort}/queue/${queues[queueDefinition]}`;
|
|
112
115
|
} else {
|
|
113
116
|
// default AWS queue URL
|
|
114
|
-
this.queues[queueDefinition] = `https://sqs.${REGION}.amazonaws.com/${
|
|
117
|
+
this.queues[queueDefinition] = `https://sqs.${REGION}.amazonaws.com/${accountId}/${queues[queueDefinition]}`;
|
|
115
118
|
}
|
|
116
119
|
});
|
|
117
120
|
}
|
|
@@ -24,8 +24,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
24
|
* @param outcome
|
|
25
25
|
*/
|
|
26
26
|
const handleSuccess = (di, outcome) => {
|
|
27
|
-
const logger = di.get(_Dependencies.DEFINITIONS.LOGGER);
|
|
28
|
-
|
|
27
|
+
const logger = di.get(_Dependencies.DEFINITIONS.LOGGER); // Outcome may be undefined as not all lambdas have a return value.
|
|
28
|
+
|
|
29
|
+
logger.metric('lambda.statusCode', outcome && outcome.statusCode || 200);
|
|
29
30
|
return outcome;
|
|
30
31
|
};
|
|
31
32
|
/**
|