I am creating a python lambda with lambda layer for the opensearch module dependency.
Locally, I pip installed opensearch-py into lambdalayerstuff/opensearchpyFolder
Here's my CDK code:
const lambdaLayerOpensearchpy = new lambda.LayerVersion(this, 'layer_3', {
code: lambda.Code.fromAsset('./lambdalayerstuff/opensearchpyFolder')
})
// lambda
const lambda1 = new lambda.Function(this, "lambda_1", {
vpc: vpc,
vpcSubnets: {
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS
},
memorySize: 512, // MB
runtime: lambda.Runtime.PYTHON_3_8,
code: lambda.Code.fromAsset(path.join(__dirname, '../src/lambda')),
handler: 'lambdacode.handler',
layers: [lambdaLayerOpensearchpy],
timeout: cdk.Duration.seconds(120)
})
Please advise on what changes I need to allow my python lambda to use opensearchpy package. Thank you.
After creating the zip, how do I reference it in the code path for the CDK layer creation?
const lambdaLayerOpensearchpy = new lambda.LayerVersion(this, 'layer_3', { code: lambda.Code.fromAsset('./lambdalayerstuff/opensearchpyFolder') })
I tried this, but still encountering the same error:
You don’t need to reference the location of the code. You just import the library
Eg
Import opensearchlibrary