Currently, I am following a tutorial by hashicorp found at this link.
The guide suggests using s3 for lambda deployment packages.
// in the process of creating Lambda executable
const asset = new TerraformAsset(this, "lambda-asset", {
path: path.resolve(__dirname, config.path),
type: AssetType.ARCHIVE, // directory and file are inferred if left empty
});
// Establising a unique S3 bucket to host the Lambda executable
const bucket = new aws.s3Bucket.S3Bucket(this, "bucket", {
bucketPrefix: `learn-cdktf-${name}`,
});
// Uploading Lambda zip file to the newly created S3 bucket
const lambdaArchive = new aws.s3Object.S3Object(this, "lambda-archive", {
bucket: bucket.bucket,
key: `${config.version}/${asset.fileName}`,
source: asset.path, // returns a posix path
});
// Creating the Lambda function
const lambdaFunc = new aws.lambdaFunction.LambdaFunction(this, "learn-cdktf-lambda", {
functionName: `learn-cdktf-${name}-${pet.id}`,
s3Bucket: bucket.bucket,
s3Key: lambdaArchive.key,
handler: config.handler,
runtime: config.runtime,
role: role.arn
});
I have managed to incorporate the synthesized code from cdktf (cdktf.json) into my existing terraform project. However, the s3 bucket object generated uses a source with a posit suffix.
"aws_s3_object": {
"lambda-archive": {
"//": {
"metadata": {
"path": "lambda-hello-world/lambda-archive",
"uniqueId": "lambda-archive"
}
},
"bucket": "${aws_s3_bucket.bucket.bucket}",
"key": "v0.0.2/archive.zip",
"source": "assets/lambda-asset/ABCDEDGHIJKLAMN000006786986/archive.zip"
}
},
When attempting to use terraform apply with cdktf.json, it indicates that the source is not found. How can I address this issue? Is there an alternative method to deploy Lambda with cdktf without utilizing s3?