@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
- [![CircleCI](https://circleci.com/gh/comicrelief/lambda-wrapper.svg?style=svg&circle-token=7db6e0ff0526bd635424f303fd4ffffc7ea05aed)](https://circleci.com/gh/comicrelief/lambda-wrapper)
3
+ ![GitHub Actions](https://github.com/comicrelief/lambda-wrapper/actions/workflows/main.yml/badge.svg)
4
4
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
5
5
  [![semantic-release](https://badge.fury.io/js/%40comicrelief%2Flambda-wrapper.svg)](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 for running end-to-end tests where a message is sent to a queue and eventually appears in an external data store.
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}:4576/queue/${queues[queueDefinition]}`;
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/${_alai.default.parse(context)}/${queues[queueDefinition]}`;
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
- logger.metric('lambda.statusCode', outcome.statusCode || 200);
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comicrelief/lambda-wrapper",
3
- "version": "1.8.2",
3
+ "version": "1.10.0",
4
4
  "description": "Lambda wrapper for all Comic Relief Serverless Projects",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {