@comicrelief/lambda-wrapper 1.8.3 → 1.9.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 +6 -1
- package/dist/Service/SQS.service.js +8 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,7 +85,12 @@ By default, messages will be sent to a SQS service running on `localhost:4576`.
|
|
|
85
85
|
|
|
86
86
|
### AWS SQS mode
|
|
87
87
|
|
|
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
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
In order for queue URLs to be correctly constructed, you must either:
|
|
91
|
+
|
|
92
|
+
- set `AWS_ACCOUNT_ID` to the account ID that hosts your queue; or
|
|
93
|
+
- invoke offline functions via the Lambda API, passing a context that contains a realistic `invokedFunctionArn` including the account ID.
|
|
89
94
|
|
|
90
95
|
## Semantic release
|
|
91
96
|
|
|
@@ -87,17 +87,19 @@ 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_MODE: offlineMode = SQS_OFFLINE_MODES.DIRECT,
|
|
93
|
+
AWS_ACCOUNT_ID,
|
|
94
|
+
REGION
|
|
95
|
+
} = process.env;
|
|
90
96
|
const container = this.getContainer();
|
|
91
97
|
const context = container.getContext();
|
|
92
98
|
const queues = container.getConfiguration('QUEUES');
|
|
99
|
+
const accountId = context && context.invokedFunctionArn && _alai.default.parse(context) || AWS_ACCOUNT_ID;
|
|
93
100
|
this.queues = {};
|
|
94
101
|
this.$lambda = null;
|
|
95
102
|
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
103
|
|
|
102
104
|
if (container.isOffline && !Object.values(SQS_OFFLINE_MODES).includes(offlineMode)) {
|
|
103
105
|
throw new Error(`Invalid LAMBDA_WRAPPER_OFFLINE_SQS_MODE: ${offlineMode}\n` + `Please use one of: ${Object.values(SQS_OFFLINE_MODES).join(', ')}`);
|
|
@@ -111,7 +113,7 @@ class SQSService extends _DependencyAware.default {
|
|
|
111
113
|
this.queues[queueDefinition] = `http://${offlineHost}:4576/queue/${queues[queueDefinition]}`;
|
|
112
114
|
} else {
|
|
113
115
|
// default AWS queue URL
|
|
114
|
-
this.queues[queueDefinition] = `https://sqs.${REGION}.amazonaws.com/${
|
|
116
|
+
this.queues[queueDefinition] = `https://sqs.${REGION}.amazonaws.com/${accountId}/${queues[queueDefinition]}`;
|
|
115
117
|
}
|
|
116
118
|
});
|
|
117
119
|
}
|