bright-wall-79582
02/14/2023, 12:35 PMaws.lambda.Function
, do I have to bundle the typescript code or can I just point it to a directory?
|- application
| | - index.ts
|- infrastructure
| | - pulumi.ts
I was following the samples doing this:
export const exampleFunction = new aws.lambda.Function('actionRunnerLambda', {
role: lambdaRole.arn,
runtime: 'nodejs18.x',
handler: 'index.handler',
code: new AssetArchive({
'.': new FileArchive('./application/')
})
})
Where index.ts
exports a âhandlerâ function.
However, when trying to upload this I get that it canât find the handler âindex.handlerâ.
I need to use the Function
to defined the Lambda as I need to specify things like the runtime and environment variables. This I can not do if I use for instance createFunctionFromEventHandler
.
I was wondering if I have to compile the typescript first and then point the file archive there?brave-planet-10645
02/14/2023, 2:58 PMcallbackFunction
resource then yes you can point it at the handlerCallbackFunction
pretty much everywhere in the AWS provider where you specify a Function
resourceimport * as aws from "@pulumi/aws";
import { BucketEvent } from "@pulumi/aws/s3";
export const onObjectCreatedLambda = (e: BucketEvent) => {
const db = new aws.sdk.DynamoDB.DocumentClient();
for (const rec of e.Records || []) {
const key = rec.s3.object.key;
let params = {
TableName: process.env.TABLENAME || "",
Item: {
'objectkey': key,
'timestamp': new Date().toISOString()
}
};
db.put(params, function (err, data) {
if (err) {
console.log("Error", err);
} else {
console.log(`Written ${key} to db`);
}
});
}
};
bright-wall-79582
02/14/2023, 3:23 PMwhich could not be serialized because it was a native code function.
or
arrow function captured 'this'. Assign 'this' to another name outside function and capture that.
is the only way to get around these to revert to using Function and then use FileAssets?brave-planet-10645
03/16/2023, 5:20 PMbright-wall-79582
03/17/2023, 7:41 AM