Skip to content

Commit 61e507a

Browse files
committed
Update for Bref v3
1 parent a0d1a77 commit 61e507a

3 files changed

Lines changed: 16 additions & 87 deletions

File tree

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,15 @@ Get a layer version:
3232
```js
3333
import { layerVersions } from '@bref.sh/layers';
3434

35-
console.log(layerVersions['php-82']['us-east-1']);
36-
console.log(layerVersions['php-82-fpm']['eu-west-3']);
35+
console.log(layerVersions['php-84']['us-east-1']);
36+
console.log(layerVersions['arm-php-84']['eu-west-3']);
3737
```
3838

3939
Helpers to get a full ARN:
4040

4141
```js
42-
import { functionLayerArn, fpmLayerArn, consoleLayerArn } from '@bref.sh/layers';
42+
import { layerArn } from '@bref.sh/layers';
4343

44-
console.log(functionLayerArn(region, '8.2'));
45-
console.log(functionLayerArn(region, '8.3', 'arm'));
46-
47-
console.log(fpmLayerArn(region, '8.2'));
48-
console.log(fpmLayerArn(region, '8.3', 'arm'));
49-
50-
console.log(consoleLayerArn(region));
44+
console.log(layerArn(region, '8.4'));
45+
console.log(layerArn(region, '8.4', 'arm'));
5146
```

layers.js

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const layerVersions = require('./layers.json');
88
* @param {'x86'|'arm'} platform
99
* @returns {string} Layer ARN
1010
*/
11-
function functionLayerArn(region, phpVersion, platform = 'x86') {
11+
function layerArn(region, phpVersion, platform = 'x86') {
1212
let layerName = 'php-' + phpVersion.replace('.', '');
1313
if (platform === 'arm') {
1414
layerName = 'arm-' + layerName;
@@ -20,42 +20,8 @@ function functionLayerArn(region, phpVersion, platform = 'x86') {
2020
return `arn:aws:lambda:${region}:873528684822:layer:${layerName}:${version}`;
2121
}
2222

23-
/**
24-
* Returns the ARN for the FPM layer.
25-
* @param {string} region
26-
* @param {string} phpVersion (e.g. '8.1')
27-
* @param {'x86'|'arm'} platform
28-
* @returns {string} Layer ARN
29-
*/
30-
function fpmLayerArn(region, phpVersion, platform = 'x86') {
31-
let layerName = 'php-' + phpVersion.replace('.', '') + '-fpm';
32-
if (platform === 'arm') {
33-
layerName = 'arm-' + layerName;
34-
}
35-
const version = layerVersions[layerName]?.[region];
36-
if (!version) {
37-
throw new Error(`PHP version ${phpVersion} in ${region} is not supported`);
38-
}
39-
return `arn:aws:lambda:${region}:873528684822:layer:${layerName}:${version}`;
40-
}
41-
42-
/**
43-
* Returns the ARN for the Console layer.
44-
* @param {string} region
45-
* @returns {string} Layer ARN
46-
*/
47-
function consoleLayerArn(region) {
48-
const version = layerVersions.console[region];
49-
if (!version) {
50-
throw new Error(`Console layer does not exist in region ${region}`);
51-
}
52-
return `arn:aws:lambda:${region}:873528684822:layer:console:${version}`;
53-
}
54-
5523
module.exports = {
5624
// Expose the JSON data as a JS dependency for easier use in programmatic environments
5725
layerVersions,
58-
functionLayerArn,
59-
fpmLayerArn,
60-
consoleLayerArn,
26+
layerArn,
6127
};

test/layers.test.js

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,33 @@
11
import {describe, test, expect} from 'vitest'
22
import layerVersions from "../layers.json";
3-
import {consoleLayerArn, fpmLayerArn, functionLayerArn} from "../layers";
3+
import {layerArn} from "../layers";
44

55
// The two tests marked with concurrent will be run in parallel
66
describe('layers', () => {
77

88
test('layerVersions', () => {
99
expect(layerVersions).to.have.keys([
10+
"php-85",
1011
"php-84",
11-
"php-84-fpm",
1212
"php-83",
13-
"php-83-fpm",
1413
"php-82",
15-
"php-82-fpm",
16-
"php-81",
17-
"php-81-fpm",
18-
"php-80",
19-
"php-80-fpm",
14+
"arm-php-85",
2015
"arm-php-84",
21-
"arm-php-84-fpm",
2216
"arm-php-83",
23-
"arm-php-83-fpm",
2417
"arm-php-82",
25-
"arm-php-82-fpm",
26-
"arm-php-81",
27-
"arm-php-81-fpm",
28-
"arm-php-80",
29-
"arm-php-80-fpm",
30-
"console",
3118
]);
3219
expect(layerVersions["php-82"]["us-east-1"]).to.be.a("string");
3320
});
3421

35-
test('functionLayerArn', () => {
36-
expect(functionLayerArn('us-east-1', '8.3')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:php-83:\d+/);
37-
expect(functionLayerArn('us-east-1', '8.3', 'arm')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:arm-php-83:\d+/);
38-
expect(functionLayerArn('us-east-1', '8.2')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:php-82:\d+/);
39-
expect(functionLayerArn('us-east-1', '8.1', 'arm')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:arm-php-81:\d+/);
22+
test('layerArn', () => {
23+
expect(layerArn('us-east-1', '8.3')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:php-83:\d+/);
24+
expect(layerArn('us-east-1', '8.3', 'arm')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:arm-php-83:\d+/);
25+
expect(layerArn('us-east-1', '8.2')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:php-82:\d+/);
26+
expect(layerArn('us-east-1', '8.5', 'arm')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:arm-php-85:\d+/);
4027

4128
expect(() => {
42-
functionLayerArn('us-east-1', '7.4', 'arm');
29+
layerArn('us-east-1', '7.4', 'arm');
4330
}).toThrow('PHP version 7.4 in us-east-1 is not supported');
4431
});
4532

46-
test('fpmLayerArn', () => {
47-
expect(fpmLayerArn('us-east-1', '8.3')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:php-83-fpm:\d+/);
48-
expect(fpmLayerArn('us-east-1', '8.3', 'arm')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:arm-php-83-fpm:\d+/);
49-
expect(fpmLayerArn('us-east-1', '8.2')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:php-82-fpm:\d+/);
50-
expect(fpmLayerArn('us-east-1', '8.1', 'arm')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:arm-php-81-fpm:\d+/);
51-
52-
expect(() => {
53-
fpmLayerArn('us-east-1', '7.4', 'arm');
54-
}).toThrow('PHP version 7.4 in us-east-1 is not supported');
55-
});
56-
57-
test('consoleLayerArn', () => {
58-
expect(consoleLayerArn('us-east-1')).matches(/arn:aws:lambda:us-east-1:873528684822:layer:console:\d+/);
59-
60-
expect(() => {
61-
consoleLayerArn('us-east-99');
62-
}).toThrow('Console layer does not exist in region us-east-99');
63-
});
64-
6533
});

0 commit comments

Comments
 (0)