I am trying to use Bref custom runtime in AWS Lambda using AWS CDK instead of Serverless.
The CDK code is like below.
const region = cdk.Stack.of(this).region;
//arn:aws:lambda:ap-southeast-1:209497400698:layer:php-74:18
const brefLayerVersion = `arn:aws:lambda:${region}:209497400698:layer:php-80:8`;
const assetPath = path.join(__dirname, '../../lambda');
const asset = lambda.Code.fromAsset(assetPath);
const lambdaFunc = new lambda.Function(this, 'LambdaFunction', {
runtime: lambda.Runtime.PROVIDED,
handler: 'src/index.php',
layers: [
lambda.LayerVersion.fromLayerVersionArn(this, 'BrefPHPLayer', brefLayerVersion),
],
code: asset,
});
new cdk.CfnOutput(this, 'LambdaFunctionArn', { value: lambdaFunc.functionArn });
Here's the full source code https://github.com/petrabarus/cdk-bref-function
When I tried manually invoking using AWS CLI aws lambda invoke --function-name arn:blabla
, it shows error.
The Cloudwatch Log shows something like this.
/opt/bin/php: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or directory
If I compare the deployment with Serverless Framework, the configuration (layer, code, etc) is pretty much the same. What did I miss?
Turns out the Bref 1.0 needs provided Amazon Linux 2 Runtime. Here's the updated CDK code.
const lambdaFunc = new lambda.Function(this, 'LambdaFunction', {
runtime: lambda.Runtime.PROVIDED_AL2,
handler: 'src/index.php',
layers: [
lambda.LayerVersion.fromLayerVersionArn(this, 'BrefPHPLayer', brefLayerVersion),
],
code: asset,
});