Image of directory I was trying to deploy a lambda stack that contains a lambda function. The code that the function will run lies in a services folder under the source folder. I run into a cannot find asset error even when the directory to my file seems to be correct in the lambda function. Does anyone know what I am missing?
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import {
Code,
Function as LambdaFunction,
Runtime,
} from "aws-cdk-lib/aws-lambda";
import { join } from "path";
export class LambdaStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new LambdaFunction(this, "getBooksLambda", {
runtime: Runtime.NODEJS_18_X,
handler: "getBooks.main",
code: Code.fromAsset(join(__dirname, "..", "..", "services", "getBooks")),
});
}
}
exports.main = async function(event, context) {
return {
statusCode: 200,
body: JSON.stringify({
message: "Hello from Lambda"
})
}
}
Error: Cannot find asset at C:UsersUserDocumentsBookeroobookeroo-cdksrcservicesgetBooks
at new AssetStaging (C:UsersUserDocumentsBookeroobookeroo-cdknode_modulesaws-cdk-libcorelibasset-staging.js:1:2119)
at new Asset (C:UsersUserDocumentsBookeroobookeroo-cdknode_modulesaws-cdk-libaws-s3-assetslibasset.js:1:1141)
at AssetCode.bind (C:UsersUserDocumentsBookeroobookeroo-cdknode_modulesaws-cdk-libaws-lambdalibcode.js:5:3487)
at new Function (C:UsersUserDocumentsBookeroobookeroo-cdknode_modulesaws-cdk-libaws-lambdalibfunction.js:1:10003)
at new LambdaStack (C:UsersUserDocumentsBookeroobookeroo-cdksrcinfrastacksLambdaStack.ts:13:32)
at Object. (C:UsersUserDocumentsBookeroobookeroo-cdksrcinfraLauncher.ts:12:1)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module.m._compile (C:UsersUserDocumentsBookeroobookeroo-cdknode_modulests-nodesrcindex.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Object.require.extensions. [as .ts] (C:UsersUserDocumentsBookeroobookeroo-cdknode_modulests-nodesrcindex.ts:1621:12)
I just tried running it expecting the cdk synth to not throw an error. I also tried moving around the getBooks file and also adding .js to the end of the directory. None of them worked