forked from datalisk/pulumi-aws-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleNodeLambda.ts
More file actions
68 lines (60 loc) · 2.26 KB
/
SimpleNodeLambda.ts
File metadata and controls
68 lines (60 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import { ComponentResourceOptions } from "@pulumi/pulumi";
import { BaseLambdaArgs, Builder } from "./Builder";
/**
* Creates a Nodejs AWS Lambda with useful defaults for small & simple tasks.
*/
export class SimpleNodeLambda extends pulumi.ComponentResource {
readonly function: aws.lambda.Function;
constructor(name: string, args: SimpleNodeLambdaArgs, opts?: ComponentResourceOptions, type?: string) {
super(type ?? "pat:lambda:SimpleNodeLambda", name, args, opts);
const builder = new Builder(name, args, { parent: this });
const logGroup = builder.createLogGroup();
const role = builder.createRole();
const vpcConfig = builder.createVpcConfig();
this.function = new aws.lambda.Function(name, {
description: args.codeDir.substring(args.codeDir.lastIndexOf('/') + 1),
code: new pulumi.asset.AssetArchive({
".": new pulumi.asset.FileArchive(args.codeDir),
}),
handler: `index.handler`,
runtime: aws.lambda.Runtime.NodeJS20dX,
architectures: ["arm64"],
role: role.arn,
memorySize: args.memorySize ?? 128,
timeout: args.timeout ?? 60,
environment: {
variables: args.environmentVariables,
},
vpcConfig,
loggingConfig: {
logGroup: logGroup.name,
logFormat: "Text",
},
}, {
parent: this
});
}
}
export interface SimpleNodeLambdaArgs extends BaseLambdaArgs {
/**
* A directory with the JS source code to deploy.
* It must contain a index.js/index.mjs file with a handler function.
*/
codeDir: string;
/**
* Map of environment variables for the function.
*/
environmentVariables?: pulumi.Input<{
[key: string]: pulumi.Input<string>;
}>;
/**
* Amount of memory in MB your Lambda Function can use at runtime. Defaults to `128`. See [Limits](https://docs.aws.amazon.com/lambda/latest/dg/limits.html)
*/
memorySize?: number;
/**
* Amount of time your Lambda Function has to run in seconds. Defaults to `60`.
*/
timeout?: number;
}