Skip to content

Commit 5656165

Browse files
authored
Merge pull request #2051 from brefphp/fix-2048
Fix `bref:cli` command in v3
2 parents 9b85d98 + b5441e9 commit 5656165

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

plugin/run-console.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
41
/**
52
* @param {import('./serverless').Serverless} serverless
63
* @param {import('./serverless').CliOptions} options
74
*/
85
async function runConsole(serverless, options) {
9-
const region = serverless.getProvider('aws').getRegion();
106
// Override CLI options for `sls invoke`
11-
options.function = options.function || getConsoleFunction(serverless, region);
7+
options.function = options.function || getConsoleFunction(serverless);
128
options.type = 'RequestResponse';
139
options.data = options.args;
1410
options.log = true;
@@ -18,36 +14,24 @@ async function runConsole(serverless, options) {
1814

1915
/**
2016
* @param {import('./serverless').Serverless} serverless
21-
* @param {string} region
2217
*/
23-
function getConsoleFunction(serverless, region) {
24-
const consoleLayerArn = getConsoleLayerArn(region);
25-
18+
function getConsoleFunction(serverless) {
2619
const functions = serverless.service.functions;
2720
const consoleFunctions = [];
2821
for (const [functionName, functionDetails] of Object.entries(functions || {})) {
29-
if (functionDetails.layers && functionDetails.layers.includes(consoleLayerArn)) {
22+
// Check for BREF_RUNTIME environment variable (set by Bref plugin for php-XX-console runtimes)
23+
const brefRuntime = functionDetails.environment && functionDetails.environment.BREF_RUNTIME;
24+
if (brefRuntime === 'Bref\\ConsoleRuntime\\Main' || brefRuntime === 'console') {
3025
consoleFunctions.push(functionName);
3126
}
3227
}
3328
if (consoleFunctions.length === 0) {
34-
throw new serverless.classes.Error('This command invokes the Lambda "console" function, but no function was found with the "console" layer');
29+
throw new serverless.classes.Error('This command invokes a Lambda console function, but no function was found using the console runtime (e.g. php-84-console)');
3530
}
3631
if (consoleFunctions.length > 1) {
37-
throw new serverless.classes.Error('More than one function contains the console layer: cannot automatically run it. Please provide a function name using the --function option.');
32+
throw new serverless.classes.Error('More than one function uses the console runtime: cannot automatically run it. Please provide a function name using the --function option.');
3833
}
3934
return consoleFunctions[0];
4035
}
4136

42-
/**
43-
* @param {string} region
44-
* @returns {string}
45-
*/
46-
function getConsoleLayerArn(region) {
47-
const json = fs.readFileSync(path.join(__dirname, '../layers.json'));
48-
const layers = JSON.parse(json.toString());
49-
const version = layers.console[region];
50-
return `arn:aws:lambda:${region}:873528684822:layer:console:${version}`;
51-
}
52-
5337
module.exports = {runConsole};

0 commit comments

Comments
 (0)