Skip to content

Commit

Permalink
Handle errors and default values
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 16, 2022
1 parent 53555f8 commit 763d149
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ const layerVersions = require('./layers.json');
* @param {'x86'|'arm'} platform
* @returns {string} Layer ARN
*/
function functionLayerArn(region, phpVersion, platform) {
function functionLayerArn(region, phpVersion, platform = 'x86') {
let layerName = 'php-' + phpVersion.replace('.', '');
if (platform === 'arm') {
layerName = 'arm-' + layerName;
}
const version = layerVersions[layerName][region];
const version = layerVersions[layerName]?.[region];
if (!version) {
throw new Error(`PHP version ${phpVersion} in ${region} is not supported`);
}
return `arn:aws:lambda:${region}:534081306603:layer:${layerName}:${version}`;
}

Expand All @@ -24,12 +27,15 @@ function functionLayerArn(region, phpVersion, platform) {
* @param {'x86'|'arm'} platform
* @returns {string} Layer ARN
*/
function fpmLayerArn(region, phpVersion, platform) {
function fpmLayerArn(region, phpVersion, platform = 'x86') {
let layerName = 'php-' + phpVersion.replace('.', '') + '-fpm';
if (platform === 'arm') {
layerName = 'arm-' + layerName;
}
const version = layerVersions[layerName][region];
const version = layerVersions[layerName]?.[region];
if (!version) {
throw new Error(`PHP version ${phpVersion} in ${region} is not supported`);
}
return `arn:aws:lambda:${region}:534081306603:layer:${layerName}:${version}`;
}

Expand All @@ -40,6 +46,9 @@ function fpmLayerArn(region, phpVersion, platform) {
*/
function consoleLayerArn(region) {
const version = layerVersions.console[region];
if (!version) {
throw new Error(`Console layer does not exist in region ${region}`);
}
return `arn:aws:lambda:${region}:534081306603:layer:console:${version}`;
}

Expand Down

0 comments on commit 763d149

Please sign in to comment.