import { LambdaFunction, S3BucketObject } from "@cdktf/provider-aws";
const asset = new TerraformAsset(stack, "my_lambda_asset", {
path: "./lambda-handler",
type: AssetType.ARCHIVE,
});
const bucket = new S3Bucket(stack, "code_bucket", {
bucket: "my-lambda-code-bucket",
});
const upload = new S3BucketObject(stack, "lambda_zip", {
bucket: bucket.bucket,
key: `code-${asset.assetHash}.zip`,
source: asset.path, // Use the synthesized path
});
new LambdaFunction(stack, "my_lambda", {
functionName: "MyFunction",
s3Bucket: bucket.bucket,
s3Key: upload.key,
handler: "index.handler",
runtime: "nodejs18.x",
role: iamRole.arn,
});