Documentation ¶
Index ¶
- func NewNodejsFunction_Override(n NodejsFunction, scope constructs.Construct, id *string, ...)
- func NodejsFunction_ClassifyVersionProperty(propertyName *string, locked *bool)
- func NodejsFunction_FromFunctionArn(scope constructs.Construct, id *string, functionArn *string) awslambda.IFunction
- func NodejsFunction_FromFunctionAttributes(scope constructs.Construct, id *string, attrs *awslambda.FunctionAttributes) awslambda.IFunction
- func NodejsFunction_FromFunctionName(scope constructs.Construct, id *string, functionName *string) awslambda.IFunction
- func NodejsFunction_IsConstruct(x interface{}) *bool
- func NodejsFunction_IsOwnedResource(construct constructs.IConstruct) *bool
- func NodejsFunction_IsResource(construct constructs.IConstruct) *bool
- func NodejsFunction_MetricAll(metricName *string, props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- func NodejsFunction_MetricAllConcurrentExecutions(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- func NodejsFunction_MetricAllDuration(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- func NodejsFunction_MetricAllErrors(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- func NodejsFunction_MetricAllInvocations(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- func NodejsFunction_MetricAllThrottles(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- func NodejsFunction_MetricAllUnreservedConcurrentExecutions(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
- type BundlingOptions
- type Charset
- type ICommandHooks
- type LogLevel
- type NodejsFunction
- type NodejsFunctionProps
- type OutputFormat
- type SourceMapMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNodejsFunction_Override ¶
func NewNodejsFunction_Override(n NodejsFunction, scope constructs.Construct, id *string, props *NodejsFunctionProps)
func NodejsFunction_ClassifyVersionProperty ¶
Record whether specific properties in the `AWS::Lambda::Function` resource should also be associated to the Version resource.
See 'currentVersion' section in the module README for more details.
func NodejsFunction_FromFunctionArn ¶
func NodejsFunction_FromFunctionArn(scope constructs.Construct, id *string, functionArn *string) awslambda.IFunction
Import a lambda function into the CDK using its ARN.
For `Function.addPermissions()` to work on this imported lambda, make sure that is in the same account and region as the stack you are importing it into.
func NodejsFunction_FromFunctionAttributes ¶
func NodejsFunction_FromFunctionAttributes(scope constructs.Construct, id *string, attrs *awslambda.FunctionAttributes) awslambda.IFunction
Creates a Lambda function object which represents a function not defined within this stack.
For `Function.addPermissions()` to work on this imported lambda, set the sameEnvironment property to true if this imported lambda is in the same account and region as the stack you are importing it into.
func NodejsFunction_FromFunctionName ¶ added in v2.14.0
func NodejsFunction_FromFunctionName(scope constructs.Construct, id *string, functionName *string) awslambda.IFunction
Import a lambda function into the CDK using its name.
func NodejsFunction_IsConstruct ¶
func NodejsFunction_IsConstruct(x interface{}) *bool
Checks if `x` is a construct.
Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.
Returns: true if `x` is an object created from a class which extends `Construct`.
func NodejsFunction_IsOwnedResource ¶ added in v2.32.0
func NodejsFunction_IsOwnedResource(construct constructs.IConstruct) *bool
Returns true if the construct was created by CDK, and false otherwise.
func NodejsFunction_IsResource ¶
func NodejsFunction_IsResource(construct constructs.IConstruct) *bool
Check whether the given construct is a Resource.
func NodejsFunction_MetricAll ¶
func NodejsFunction_MetricAll(metricName *string, props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Return the given named metric for this Lambda.
func NodejsFunction_MetricAllConcurrentExecutions ¶
func NodejsFunction_MetricAllConcurrentExecutions(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Metric for the number of concurrent executions across all Lambdas. Default: max over 5 minutes.
func NodejsFunction_MetricAllDuration ¶
func NodejsFunction_MetricAllDuration(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Metric for the Duration executing all Lambdas. Default: average over 5 minutes.
func NodejsFunction_MetricAllErrors ¶
func NodejsFunction_MetricAllErrors(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Metric for the number of Errors executing all Lambdas. Default: sum over 5 minutes.
func NodejsFunction_MetricAllInvocations ¶
func NodejsFunction_MetricAllInvocations(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Metric for the number of invocations of all Lambdas. Default: sum over 5 minutes.
func NodejsFunction_MetricAllThrottles ¶
func NodejsFunction_MetricAllThrottles(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Metric for the number of throttled invocations of all Lambdas. Default: sum over 5 minutes.
func NodejsFunction_MetricAllUnreservedConcurrentExecutions ¶
func NodejsFunction_MetricAllUnreservedConcurrentExecutions(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
Metric for the number of unreserved concurrent executions across all Lambdas. Default: max over 5 minutes.
Types ¶
type BundlingOptions ¶
type BundlingOptions struct { // The command to run in the container. // Default: - run the command defined in the image. // Command *[]*string `field:"optional" json:"command" yaml:"command"` // The entrypoint to run in the container. // Default: - run the entrypoint defined in the image. // Entrypoint *[]*string `field:"optional" json:"entrypoint" yaml:"entrypoint"` // The environment variables to pass to the container. // Default: - no environment variables. // Environment *map[string]*string `field:"optional" json:"environment" yaml:"environment"` // Docker [Networking options](https://docs.docker.com/engine/reference/commandline/run/#connect-a-container-to-a-network---network). // Default: - no networking options. // Network *string `field:"optional" json:"network" yaml:"network"` // Set platform if server is multi-platform capable. _Requires Docker Engine API v1.38+_. // // Example value: `linux/amd64`. // Default: - no platform specified. // Platform *string `field:"optional" json:"platform" yaml:"platform"` // [Security configuration](https://docs.docker.com/engine/reference/run/#security-configuration) when running the docker container. // Default: - no security options. // SecurityOpt *string `field:"optional" json:"securityOpt" yaml:"securityOpt"` // The user to use when running the container. // Default: - root or image default. // User *string `field:"optional" json:"user" yaml:"user"` // Docker volumes to mount. // Default: - no volumes are mounted. // Volumes *[]*awscdk.DockerVolume `field:"optional" json:"volumes" yaml:"volumes"` // Where to mount the specified volumes from. // See: https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container---volumes-from // // Default: - no containers are specified to mount volumes from. // VolumesFrom *[]*string `field:"optional" json:"volumesFrom" yaml:"volumesFrom"` // Working directory inside the container. // Default: - image default. // WorkingDirectory *string `field:"optional" json:"workingDirectory" yaml:"workingDirectory"` // Specify a custom hash for this asset. // // For consistency, this custom hash will // be SHA256 hashed and encoded as hex. The resulting hash will be the asset // hash. // // NOTE: the hash is used in order to identify a specific revision of the asset, and // used for optimizing and caching deployment activities related to this asset such as // packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will // need to make sure it is updated every time the asset changes, or otherwise it is // possible that some deployments will not be invalidated. // Default: - asset hash is calculated based on the bundled output. // AssetHash *string `field:"optional" json:"assetHash" yaml:"assetHash"` // Use this to insert an arbitrary string at the beginning of generated JavaScript files. // // This is similar to footer which inserts at the end instead of the beginning. // // This is commonly used to insert comments:. // Default: - no comments are passed. // Banner *string `field:"optional" json:"banner" yaml:"banner"` // Build arguments to pass when building the bundling image. // Default: - no build arguments are passed. // BuildArgs *map[string]*string `field:"optional" json:"buildArgs" yaml:"buildArgs"` // Includes AWS SDK in the bundle asset. // Default: - false // if `true` the `aws-sdk` will be included in the asset bundle and not be // resolved to the Lambda provided sdk. // BundleAwsSDK *bool `field:"optional" json:"bundleAwsSDK" yaml:"bundleAwsSDK"` // Which option to use to copy the source files to the docker container and output files back. // Default: - BundlingFileAccess.BIND_MOUNT // BundlingFileAccess awscdk.BundlingFileAccess `field:"optional" json:"bundlingFileAccess" yaml:"bundlingFileAccess"` // The charset to use for esbuild's output. // // By default esbuild's output is ASCII-only. Any non-ASCII characters are escaped // using backslash escape sequences. Using escape sequences makes the generated output // slightly bigger, and also makes it harder to read. If you would like for esbuild to print // the original characters without using escape sequences, use `Charset.UTF8`. // See: https://esbuild.github.io/api/#charset // // Default: Charset.ASCII // Charset Charset `field:"optional" json:"charset" yaml:"charset"` // Command hooks. // Default: - do not run additional commands. // CommandHooks ICommandHooks `field:"optional" json:"commandHooks" yaml:"commandHooks"` // Replace global identifiers with constant expressions. // // For example, `{ 'process.env.DEBUG': 'true' }`. // // Another example, `{ 'process.env.API_KEY': JSON.stringify('xxx-xxxx-xxx') }`. // Default: - no replacements are made. // Define *map[string]*string `field:"optional" json:"define" yaml:"define"` // A custom bundling Docker image. // // This image should have esbuild installed globally. If you plan to use `nodeModules` // it should also have `npm`, `yarn`, `bun` or `pnpm` depending on the lock file you're using. // // See https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile // for the default image provided by aws-cdk-lib/aws-lambda-nodejs. // Default: - use the Docker image provided by aws-cdk-lib/aws-lambda-nodejs. // DockerImage awscdk.DockerImage `field:"optional" json:"dockerImage" yaml:"dockerImage"` // Build arguments to pass into esbuild. // // For example, to add the [--log-limit](https://esbuild.github.io/api/#log-limit) flag: // // “`text // new NodejsFunction(scope, id, { // ... // bundling: { // esbuildArgs: { // "--log-limit": "0", // } // } // }); // “`. // Default: - no additional esbuild arguments are passed. // EsbuildArgs *map[string]interface{} `field:"optional" json:"esbuildArgs" yaml:"esbuildArgs"` // The version of esbuild to use when running in a Docker container. // Default: - latest v0. // EsbuildVersion *string `field:"optional" json:"esbuildVersion" yaml:"esbuildVersion"` // A list of modules that should be considered as externals (already available in the runtime). // Default: - no replacements are made. // ExternalModules *[]*string `field:"optional" json:"externalModules" yaml:"externalModules"` // // This is similar to banner which inserts at the beginning instead of the end. // // This is commonly used to insert comments. // Default: - no comments are passed. // Footer *string `field:"optional" json:"footer" yaml:"footer"` // Force bundling in a Docker container even if local bundling is possible. // // This is useful if your function relies on node modules // that should be installed (`nodeModules`) in a Lambda compatible // environment. // Default: false. // ForceDockerBundling *bool `field:"optional" json:"forceDockerBundling" yaml:"forceDockerBundling"` // Output format for the generated JavaScript files. // Default: OutputFormat.CJS // Format OutputFormat `field:"optional" json:"format" yaml:"format"` // This option allows you to automatically replace a global variable with an import from another file. // See: https://esbuild.github.io/api/#inject // // Default: - no code is injected. // Inject *[]*string `field:"optional" json:"inject" yaml:"inject"` // Whether to preserve the original `name` values even in minified code. // // In JavaScript the `name` property on functions and classes defaults to a // nearby identifier in the source code. // // However, minification renames symbols to reduce code size and bundling // sometimes need to rename symbols to avoid collisions. That changes value of // the `name` property for many of these cases. This is usually fine because // the `name` property is normally only used for debugging. However, some // frameworks rely on the `name` property for registration and binding purposes. // If this is the case, you can enable this option to preserve the original // `name` values even in minified code. // Default: false. // KeepNames *bool `field:"optional" json:"keepNames" yaml:"keepNames"` // Use loaders to change how a given input file is interpreted. // // Configuring a loader for a given file type lets you load that file type with // an `import` statement or a `require` call. // // For example, `{ '.png': 'dataurl' }`. // See: https://esbuild.github.io/api/#loader // // Default: - use esbuild default loaders. // Loader *map[string]*string `field:"optional" json:"loader" yaml:"loader"` // Log level for esbuild. // // This is also propagated to the package manager and // applies to its specific install command. // Default: LogLevel.WARNING // LogLevel LogLevel `field:"optional" json:"logLevel" yaml:"logLevel"` // How to determine the entry point for modules. // // Try ['module', 'main'] to default to ES module versions. // Default: []. // MainFields *[]*string `field:"optional" json:"mainFields" yaml:"mainFields"` // This option tells esbuild to write out a JSON file relative to output directory with metadata about the build. // // The metadata in this JSON file follows this schema (specified using TypeScript syntax): // // “`text // { // outputs: { // [path: string]: { // bytes: number // inputs: { // [path: string]: { bytesInOutput: number } // } // imports: { path: string }[] // exports: string[] // } // } // } // “` // This data can then be analyzed by other tools. For example, // bundle buddy can consume esbuild's metadata format and generates a treemap visualization // of the modules in your bundle and how much space each one takes up. // See: https://esbuild.github.io/api/#metafile // // Default: false. // Metafile *bool `field:"optional" json:"metafile" yaml:"metafile"` // Whether to minify files when bundling. // Default: false. // Minify *bool `field:"optional" json:"minify" yaml:"minify"` // A list of modules that should be installed instead of bundled. // // Modules are // installed in a Lambda compatible environment only when bundling runs in // Docker. // Default: - all modules are bundled. // NodeModules *[]*string `field:"optional" json:"nodeModules" yaml:"nodeModules"` // Run compilation using tsc before running file through bundling step. // // This usually is not required unless you are using new experimental features that // are only supported by typescript's `tsc` compiler. // One example of such feature is `emitDecoratorMetadata`. // Default: false. // PreCompilation *bool `field:"optional" json:"preCompilation" yaml:"preCompilation"` // Whether to include source maps when bundling. // Default: false. // SourceMap *bool `field:"optional" json:"sourceMap" yaml:"sourceMap"` // Source map mode to be used when bundling. // See: https://esbuild.github.io/api/#sourcemap // // Default: SourceMapMode.DEFAULT // SourceMapMode SourceMapMode `field:"optional" json:"sourceMapMode" yaml:"sourceMapMode"` // Whether to include original source code in source maps when bundling. // See: https://esbuild.github.io/api/#sources-content // // Default: true. // SourcesContent *bool `field:"optional" json:"sourcesContent" yaml:"sourcesContent"` // Target environment for the generated JavaScript code. // See: https://esbuild.github.io/api/#target // // Default: - the node version of the runtime. // Target *string `field:"optional" json:"target" yaml:"target"` // Normally the esbuild automatically discovers `tsconfig.json` files and reads their contents during a build. // // However, you can also configure a custom `tsconfig.json` file to use instead. // // This is similar to entry path, you need to provide path to your custom `tsconfig.json`. // // This can be useful if you need to do multiple builds of the same code with different settings. // // For example, `{ 'tsconfig': 'path/custom.tsconfig.json' }`. // Default: - automatically discovered by `esbuild`. // Tsconfig *string `field:"optional" json:"tsconfig" yaml:"tsconfig"` }
Bundling options.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ DockerImage: awscdk.DockerImage_FromBuild(jsii.String("/path/to/Dockerfile")), }, })
type Charset ¶
type Charset string
Charset for esbuild's output.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ Minify: jsii.Boolean(true), // minify code, defaults to false SourceMap: jsii.Boolean(true), // include source map, defaults to false SourceMapMode: nodejs.SourceMapMode_INLINE, // defaults to SourceMapMode.DEFAULT SourcesContent: jsii.Boolean(false), // do not include original source into source map, defaults to true Target: jsii.String("es2020"), // target environment for the generated JavaScript code Loader: map[string]*string{ // Use the 'dataurl' loader for '.png' files ".png": jsii.String("dataurl"), }, Define: map[string]*string{ // Replace strings during build time "process.env.API_KEY": JSON.stringify(jsii.String("xxx-xxxx-xxx")), "process.env.PRODUCTION": JSON.stringify(jsii.Boolean(true)), "process.env.NUMBER": JSON.stringify(jsii.Number(123)), }, LogLevel: nodejs.LogLevel_ERROR, // defaults to LogLevel.WARNING KeepNames: jsii.Boolean(true), // defaults to false Tsconfig: jsii.String("custom-tsconfig.json"), // use custom-tsconfig.json instead of default, Metafile: jsii.Boolean(true), // include meta file, defaults to false Banner: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Footer: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Charset: nodejs.Charset_UTF8, // do not escape non-ASCII characters, defaults to Charset.ASCII Format: nodejs.OutputFormat_ESM, // ECMAScript module output format, defaults to OutputFormat.CJS (OutputFormat.ESM requires Node.js >= 14) MainFields: []*string{ jsii.String("module"), jsii.String("main"), }, // prefer ECMAScript versions of dependencies Inject: []*string{ jsii.String("./my-shim.js"), jsii.String("./other-shim.js"), }, // allows to automatically replace a global variable with an import from another file EsbuildArgs: map[string]interface{}{ // Pass additional arguments to esbuild "--log-limit": jsii.String("0"), "--splitting": jsii.Boolean(true), }, }, })
type ICommandHooks ¶
type ICommandHooks interface { // Returns commands to run after bundling. // // Commands are chained with `&&`. AfterBundling(inputDir *string, outputDir *string) *[]*string // Returns commands to run before bundling. // // Commands are chained with `&&`. BeforeBundling(inputDir *string, outputDir *string) *[]*string // Returns commands to run before installing node modules. // // This hook only runs when node modules are installed. // // Commands are chained with `&&`. BeforeInstall(inputDir *string, outputDir *string) *[]*string }
Command hooks.
These commands will run in the environment in which bundling occurs: inside the container for Docker bundling or on the host OS for local bundling.
Commands are chained with `&&`.
The following example (specified in TypeScript) copies a file from the input directory to the output directory to include it in the bundled asset:
```text
afterBundling(inputDir: string, outputDir: string): string[]{ return [`cp ${inputDir}/my-binary.node ${outputDir}`]; }
```.
type LogLevel ¶
type LogLevel string
Log levels for esbuild and package managers' install commands.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ Minify: jsii.Boolean(true), // minify code, defaults to false SourceMap: jsii.Boolean(true), // include source map, defaults to false SourceMapMode: nodejs.SourceMapMode_INLINE, // defaults to SourceMapMode.DEFAULT SourcesContent: jsii.Boolean(false), // do not include original source into source map, defaults to true Target: jsii.String("es2020"), // target environment for the generated JavaScript code Loader: map[string]*string{ // Use the 'dataurl' loader for '.png' files ".png": jsii.String("dataurl"), }, Define: map[string]*string{ // Replace strings during build time "process.env.API_KEY": JSON.stringify(jsii.String("xxx-xxxx-xxx")), "process.env.PRODUCTION": JSON.stringify(jsii.Boolean(true)), "process.env.NUMBER": JSON.stringify(jsii.Number(123)), }, LogLevel: nodejs.LogLevel_ERROR, // defaults to LogLevel.WARNING KeepNames: jsii.Boolean(true), // defaults to false Tsconfig: jsii.String("custom-tsconfig.json"), // use custom-tsconfig.json instead of default, Metafile: jsii.Boolean(true), // include meta file, defaults to false Banner: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Footer: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Charset: nodejs.Charset_UTF8, // do not escape non-ASCII characters, defaults to Charset.ASCII Format: nodejs.OutputFormat_ESM, // ECMAScript module output format, defaults to OutputFormat.CJS (OutputFormat.ESM requires Node.js >= 14) MainFields: []*string{ jsii.String("module"), jsii.String("main"), }, // prefer ECMAScript versions of dependencies Inject: []*string{ jsii.String("./my-shim.js"), jsii.String("./other-shim.js"), }, // allows to automatically replace a global variable with an import from another file EsbuildArgs: map[string]interface{}{ // Pass additional arguments to esbuild "--log-limit": jsii.String("0"), "--splitting": jsii.Boolean(true), }, }, })
const ( // Show everything. LogLevel_VERBOSE LogLevel = "VERBOSE" // Show everything from info and some additional messages for debugging. LogLevel_DEBUG LogLevel = "DEBUG" // Show warnings, errors, and an output file summary. LogLevel_INFO LogLevel = "INFO" // Show warnings and errors. LogLevel_WARNING LogLevel = "WARNING" // Show errors only. LogLevel_ERROR LogLevel = "ERROR" // Show nothing. LogLevel_SILENT LogLevel = "SILENT" )
type NodejsFunction ¶
type NodejsFunction interface { awslambda.Function // The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64). Architecture() awslambda.Architecture // Whether the addPermission() call adds any permissions. // // True for new Lambdas, false for version $LATEST and imported Lambdas // from different accounts. CanCreatePermissions() *bool // Access the Connections object. // // Will fail if not a VPC-enabled Lambda Function. Connections() awsec2.Connections // Returns a `lambda.Version` which represents the current version of this Lambda function. A new version will be created every time the function's configuration changes. // // You can specify options for this version using the `currentVersionOptions` // prop when initializing the `lambda.Function`. CurrentVersion() awslambda.Version // The DLQ (as queue) associated with this Lambda Function (this is an optional attribute). DeadLetterQueue() awssqs.IQueue // The DLQ (as topic) associated with this Lambda Function (this is an optional attribute). DeadLetterTopic() awssns.ITopic // The environment this resource belongs to. // // For resources that are created and managed by the CDK // (generally, those created by creating new class instances like Role, Bucket, etc.), // this is always the same as the environment of the stack they belong to; // however, for imported resources // (those obtained from static methods like fromRoleArn, fromBucketName, etc.), // that might be different than the stack they were imported into. Env() *awscdk.ResourceEnvironment // ARN of this function. FunctionArn() *string // Name of this function. FunctionName() *string // The principal this Lambda Function is running as. GrantPrincipal() awsiam.IPrincipal // Whether or not this Lambda function was bound to a VPC. // // If this is is `false`, trying to access the `connections` object will fail. IsBoundToVpc() *bool // The `$LATEST` version of this function. // // Note that this is reference to a non-specific AWS Lambda version, which // means the function this version refers to can return different results in // different invocations. // // To obtain a reference to an explicit version which references the current // function configuration, use `lambdaFunction.currentVersion` instead. LatestVersion() awslambda.IVersion // The LogGroup where the Lambda function's logs are made available. // // If either `logRetention` is set or this property is called, a CloudFormation custom resource is added to the stack that // pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the correct log retention // period (never expire, by default). // // Further, if the log group already exists and the `logRetention` is not set, the custom resource will reset the log retention // to never expire even if it was configured with a different value. LogGroup() awslogs.ILogGroup // The tree node. Node() constructs.Node // The construct node where permissions are attached. PermissionsNode() constructs.Node // Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource. // // This value will resolve to one of the following: // - a concrete value (e.g. `"my-awesome-bucket"`) // - `undefined`, when a name should be generated by CloudFormation // - a concrete name generated automatically during synthesis, in // cross-environment scenarios. PhysicalName() *string // The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke(). ResourceArnsForGrantInvoke() *[]*string // Execution role associated with this function. Role() awsiam.IRole // The runtime configured for this lambda. Runtime() awslambda.Runtime // The stack in which this resource is defined. Stack() awscdk.Stack // The timeout configured for this lambda. Timeout() awscdk.Duration // Defines an alias for this function. // // The alias will automatically be updated to point to the latest version of // the function as it is being updated during a deployment. // // “`ts // declare const fn: lambda.Function; // // fn.addAlias('Live'); // // // Is equivalent to // // new lambda.Alias(this, 'AliasLive', { // aliasName: 'Live', // version: fn.currentVersion, // }); // “`. AddAlias(aliasName *string, options *awslambda.AliasOptions) awslambda.Alias // Adds an environment variable to this Lambda function. // // If this is a ref to a Lambda function, this operation results in a no-op. AddEnvironment(key *string, value *string, options *awslambda.EnvironmentOptions) awslambda.Function // Adds an event source to this function. // // Event sources are implemented in the aws-cdk-lib/aws-lambda-event-sources module. // // The following example adds an SQS Queue as an event source: // “` // import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'; // myFunction.addEventSource(new SqsEventSource(myQueue)); // “`. AddEventSource(source awslambda.IEventSource) // Adds an event source that maps to this AWS Lambda function. AddEventSourceMapping(id *string, options *awslambda.EventSourceMappingOptions) awslambda.EventSourceMapping // Adds a url to this lambda function. AddFunctionUrl(options *awslambda.FunctionUrlOptions) awslambda.FunctionUrl // Adds one or more Lambda Layers to this Lambda function. AddLayers(layers ...awslambda.ILayerVersion) // Adds a permission to the Lambda resource policy. // See: Permission for details. // AddPermission(id *string, permission *awslambda.Permission) // Adds a statement to the IAM role assumed by the instance. AddToRolePolicy(statement awsiam.PolicyStatement) // Apply the given removal policy to this resource. // // The Removal Policy controls what happens to this resource when it stops // being managed by CloudFormation, either because you've removed it from the // CDK application or because you've made a change that requires the resource // to be replaced. // // The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS // account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). ApplyRemovalPolicy(policy awscdk.RemovalPolicy) // Configures options for asynchronous invocation. ConfigureAsyncInvoke(options *awslambda.EventInvokeConfigOptions) // A warning will be added to functions under the following conditions: - permissions that include `lambda:InvokeFunction` are added to the unqualified function. // // - function.currentVersion is invoked before or after the permission is created. // // This applies only to permissions on Lambda functions, not versions or aliases. // This function is overridden as a noOp for QualifiedFunctionBase. ConsiderWarningOnInvokeFunctionPermissions(scope constructs.Construct, action *string) GeneratePhysicalName() *string // Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. `bucket.bucketArn`). // // Normally, this token will resolve to `arnAttr`, but if the resource is // referenced across environments, `arnComponents` will be used to synthesize // a concrete ARN with the resource's physical name. Make sure to reference // `this.physicalName` in `arnComponents`. GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string // Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. `bucket.bucketName`). // // Normally, this token will resolve to `nameAttr`, but if the resource is // referenced across environments, it will be resolved to `this.physicalName`, // which will be a concrete name. GetResourceNameAttribute(nameAttr *string) *string // Grant the given identity permissions to invoke this Lambda. GrantInvoke(grantee awsiam.IGrantable) awsiam.Grant // Grant multiple principals the ability to invoke this Lambda via CompositePrincipal. GrantInvokeCompositePrincipal(compositePrincipal awsiam.CompositePrincipal) *[]awsiam.Grant // Grant the given identity permissions to invoke the $LATEST version or unqualified version of this Lambda. GrantInvokeLatestVersion(grantee awsiam.IGrantable) awsiam.Grant // Grant the given identity permissions to invoke this Lambda Function URL. GrantInvokeUrl(grantee awsiam.IGrantable) awsiam.Grant // Grant the given identity permissions to invoke the given version of this Lambda. GrantInvokeVersion(grantee awsiam.IGrantable, version awslambda.IVersion) awsiam.Grant // Mix additional information into the hash of the Version object. // // The Lambda Function construct does its best to automatically create a new // Version when anything about the Function changes (its code, its layers, // any of the other properties). // // However, you can sometimes source information from places that the CDK cannot // look into, like the deploy-time values of SSM parameters. In those cases, // the CDK would not force the creation of a new Version object when it actually // should. // // This method can be used to invalidate the current Version object. Pass in // any string into this method, and make sure the string changes when you know // a new Version needs to be created. // // This method may be called more than once. InvalidateVersionBasedOn(x *string) // Return the given named metric for this Function. Metric(metricName *string, props *awscloudwatch.MetricOptions) awscloudwatch.Metric // How long execution of this Lambda takes. // // Average over 5 minutes. MetricDuration(props *awscloudwatch.MetricOptions) awscloudwatch.Metric // How many invocations of this Lambda fail. // // Sum over 5 minutes. MetricErrors(props *awscloudwatch.MetricOptions) awscloudwatch.Metric // How often this Lambda is invoked. // // Sum over 5 minutes. MetricInvocations(props *awscloudwatch.MetricOptions) awscloudwatch.Metric // How often this Lambda is throttled. // // Sum over 5 minutes. MetricThrottles(props *awscloudwatch.MetricOptions) awscloudwatch.Metric // Returns a string representation of this construct. ToString() *string WarnInvokeFunctionPermissions(scope constructs.Construct) }
A Node.js Lambda function bundled using esbuild.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ Network: jsii.String("host"), SecurityOpt: jsii.String("no-new-privileges"), User: jsii.String("user:group"), VolumesFrom: []*string{ jsii.String("777f7dc92da7"), }, Volumes: []dockerVolume{ &dockerVolume{ HostPath: jsii.String("/host-path"), ContainerPath: jsii.String("/container-path"), }, }, }, })
func NewNodejsFunction ¶
func NewNodejsFunction(scope constructs.Construct, id *string, props *NodejsFunctionProps) NodejsFunction
type NodejsFunctionProps ¶
type NodejsFunctionProps struct { // The maximum age of a request that Lambda sends to a function for processing. // // Minimum: 60 seconds // Maximum: 6 hours. // Default: Duration.hours(6) // MaxEventAge awscdk.Duration `field:"optional" json:"maxEventAge" yaml:"maxEventAge"` // The destination for failed invocations. // Default: - no destination. // OnFailure awslambda.IDestination `field:"optional" json:"onFailure" yaml:"onFailure"` // The destination for successful invocations. // Default: - no destination. // OnSuccess awslambda.IDestination `field:"optional" json:"onSuccess" yaml:"onSuccess"` // The maximum number of times to retry when the function returns an error. // // Minimum: 0 // Maximum: 2. // Default: 2. // RetryAttempts *float64 `field:"optional" json:"retryAttempts" yaml:"retryAttempts"` // Specify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation. // See: https://aws-otel.github.io/docs/getting-started/lambda // // Default: - No ADOT instrumentation. // AdotInstrumentation *awslambda.AdotInstrumentationConfig `field:"optional" json:"adotInstrumentation" yaml:"adotInstrumentation"` // Whether to allow the Lambda to send all ipv6 network traffic. // // If set to true, there will only be a single egress rule which allows all // outbound ipv6 traffic. If set to false, you must individually add traffic rules to allow the // Lambda to connect to network targets using ipv6. // // Do not specify this property if the `securityGroups` or `securityGroup` property is set. // Instead, configure `allowAllIpv6Outbound` directly on the security group. // Default: false. // AllowAllIpv6Outbound *bool `field:"optional" json:"allowAllIpv6Outbound" yaml:"allowAllIpv6Outbound"` // Whether to allow the Lambda to send all network traffic (except ipv6). // // If set to false, you must individually add traffic rules to allow the // Lambda to connect to network targets. // // Do not specify this property if the `securityGroups` or `securityGroup` property is set. // Instead, configure `allowAllOutbound` directly on the security group. // Default: true. // AllowAllOutbound *bool `field:"optional" json:"allowAllOutbound" yaml:"allowAllOutbound"` // Lambda Functions in a public subnet can NOT access the internet. // // Use this property to acknowledge this limitation and still place the function in a public subnet. // See: https://stackoverflow.com/questions/52992085/why-cant-an-aws-lambda-function-inside-a-public-subnet-in-a-vpc-connect-to-the/52994841#52994841 // // Default: false. // AllowPublicSubnet *bool `field:"optional" json:"allowPublicSubnet" yaml:"allowPublicSubnet"` // Sets the application log level for the function. // Default: "INFO". // // Deprecated: Use `applicationLogLevelV2` as a property instead. ApplicationLogLevel *string `field:"optional" json:"applicationLogLevel" yaml:"applicationLogLevel"` // Sets the application log level for the function. // Default: ApplicationLogLevel.INFO // ApplicationLogLevelV2 awslambda.ApplicationLogLevel `field:"optional" json:"applicationLogLevelV2" yaml:"applicationLogLevelV2"` // The system architectures compatible with this lambda function. // Default: Architecture.X86_64 // Architecture awslambda.Architecture `field:"optional" json:"architecture" yaml:"architecture"` // Code signing config associated with this function. // Default: - Not Sign the Code. // CodeSigningConfig awslambda.ICodeSigningConfig `field:"optional" json:"codeSigningConfig" yaml:"codeSigningConfig"` // Options for the `lambda.Version` resource automatically created by the `fn.currentVersion` method. // Default: - default options as described in `VersionOptions`. // CurrentVersionOptions *awslambda.VersionOptions `field:"optional" json:"currentVersionOptions" yaml:"currentVersionOptions"` // The SQS queue to use if DLQ is enabled. // // If SNS topic is desired, specify `deadLetterTopic` property instead. // Default: - SQS queue with 14 day retention period if `deadLetterQueueEnabled` is `true`. // DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"` // Enabled DLQ. // // If `deadLetterQueue` is undefined, // an SQS queue with default options will be defined for your Function. // Default: - false unless `deadLetterQueue` is set, which implies DLQ is enabled. // DeadLetterQueueEnabled *bool `field:"optional" json:"deadLetterQueueEnabled" yaml:"deadLetterQueueEnabled"` // The SNS topic to use as a DLQ. // // Note that if `deadLetterQueueEnabled` is set to `true`, an SQS queue will be created // rather than an SNS topic. Using an SNS topic as a DLQ requires this property to be set explicitly. // Default: - no SNS topic. // DeadLetterTopic awssns.ITopic `field:"optional" json:"deadLetterTopic" yaml:"deadLetterTopic"` // A description of the function. // Default: - No description. // Description *string `field:"optional" json:"description" yaml:"description"` // Key-value pairs that Lambda caches and makes available for your Lambda functions. // // Use environment variables to apply configuration changes, such // as test and production environment configurations, without changing your // Lambda function source code. // Default: - No environment variables. // Environment *map[string]*string `field:"optional" json:"environment" yaml:"environment"` // The AWS KMS key that's used to encrypt your function's environment variables. // Default: - AWS Lambda creates and uses an AWS managed customer master key (CMK). // EnvironmentEncryption awskms.IKey `field:"optional" json:"environmentEncryption" yaml:"environmentEncryption"` // The size of the function’s /tmp directory in MiB. // Default: 512 MiB. // EphemeralStorageSize awscdk.Size `field:"optional" json:"ephemeralStorageSize" yaml:"ephemeralStorageSize"` // Event sources for this function. // // You can also add event sources using `addEventSource`. // Default: - No event sources. // Events *[]awslambda.IEventSource `field:"optional" json:"events" yaml:"events"` // The filesystem configuration for the lambda function. // Default: - will not mount any filesystem. // Filesystem awslambda.FileSystem `field:"optional" json:"filesystem" yaml:"filesystem"` // A name for the function. // Default: - AWS CloudFormation generates a unique physical ID and uses that // ID for the function's name. For more information, see Name Type. // FunctionName *string `field:"optional" json:"functionName" yaml:"functionName"` // Initial policy statements to add to the created Lambda Role. // // You can call `addToRolePolicy` to the created lambda to add statements post creation. // Default: - No policy statements are added to the created Lambda role. // InitialPolicy *[]awsiam.PolicyStatement `field:"optional" json:"initialPolicy" yaml:"initialPolicy"` // Specify the version of CloudWatch Lambda insights to use for monitoring. // See: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-Getting-Started-docker.html // // Default: - No Lambda Insights. // InsightsVersion awslambda.LambdaInsightsVersion `field:"optional" json:"insightsVersion" yaml:"insightsVersion"` // Allows outbound IPv6 traffic on VPC functions that are connected to dual-stack subnets. // // Only used if 'vpc' is supplied. // Default: false. // Ipv6AllowedForDualStack *bool `field:"optional" json:"ipv6AllowedForDualStack" yaml:"ipv6AllowedForDualStack"` // A list of layers to add to the function's execution environment. // // You can configure your Lambda function to pull in // additional code during initialization in the form of layers. Layers are packages of libraries or other dependencies // that can be used by multiple functions. // Default: - No layers. // Layers *[]awslambda.ILayerVersion `field:"optional" json:"layers" yaml:"layers"` // Sets the logFormat for the function. // Default: "Text". // // Deprecated: Use `loggingFormat` as a property instead. LogFormat *string `field:"optional" json:"logFormat" yaml:"logFormat"` // Sets the loggingFormat for the function. // Default: LoggingFormat.TEXT // LoggingFormat awslambda.LoggingFormat `field:"optional" json:"loggingFormat" yaml:"loggingFormat"` // The log group the function sends logs to. // // By default, Lambda functions send logs to an automatically created default log group named /aws/lambda/\<function name\>. // However you cannot change the properties of this auto-created log group using the AWS CDK, e.g. you cannot set a different log retention. // // Use the `logGroup` property to create a fully customizable LogGroup ahead of time, and instruct the Lambda function to send logs to it. // // Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16. // If you are deploying to another type of region, please check regional availability first. // Default: `/aws/lambda/${this.functionName}` - default log group created by Lambda // LogGroup awslogs.ILogGroup `field:"optional" json:"logGroup" yaml:"logGroup"` // The number of days log events are kept in CloudWatch Logs. // // When updating // this property, unsetting it doesn't remove the log retention policy. To // remove the retention policy, set the value to `INFINITE`. // // This is a legacy API and we strongly recommend you move away from it if you can. // Instead create a fully customizable log group with `logs.LogGroup` and use the `logGroup` property // to instruct the Lambda function to send logs to it. // Migrating from `logRetention` to `logGroup` will cause the name of the log group to change. // Users and code and referencing the name verbatim will have to adjust. // // In AWS CDK code, you can access the log group name directly from the LogGroup construct: // “`ts // import * as logs from 'aws-cdk-lib/aws-logs'; // // declare const myLogGroup: logs.LogGroup; // myLogGroup.logGroupName; // “`. // Default: logs.RetentionDays.INFINITE // LogRetention awslogs.RetentionDays `field:"optional" json:"logRetention" yaml:"logRetention"` // When log retention is specified, a custom resource attempts to create the CloudWatch log group. // // These options control the retry policy when interacting with CloudWatch APIs. // // This is a legacy API and we strongly recommend you migrate to `logGroup` if you can. // `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it. // Default: - Default AWS SDK retry options. // LogRetentionRetryOptions *awslambda.LogRetentionRetryOptions `field:"optional" json:"logRetentionRetryOptions" yaml:"logRetentionRetryOptions"` // The IAM role for the Lambda function associated with the custom resource that sets the retention policy. // // This is a legacy API and we strongly recommend you migrate to `logGroup` if you can. // `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it. // Default: - A new role is created. // LogRetentionRole awsiam.IRole `field:"optional" json:"logRetentionRole" yaml:"logRetentionRole"` // The amount of memory, in MB, that is allocated to your Lambda function. // // Lambda uses this value to proportionally allocate the amount of CPU // power. For more information, see Resource Model in the AWS Lambda // Developer Guide. // Default: 128. // MemorySize *float64 `field:"optional" json:"memorySize" yaml:"memorySize"` // Specify the configuration of Parameters and Secrets Extension. // See: https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html // // Default: - No Parameters and Secrets Extension. // ParamsAndSecrets awslambda.ParamsAndSecretsLayerVersion `field:"optional" json:"paramsAndSecrets" yaml:"paramsAndSecrets"` // Enable profiling. // See: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html // // Default: - No profiling. // Profiling *bool `field:"optional" json:"profiling" yaml:"profiling"` // Profiling Group. // See: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html // // Default: - A new profiling group will be created if `profiling` is set. // ProfilingGroup awscodeguruprofiler.IProfilingGroup `field:"optional" json:"profilingGroup" yaml:"profilingGroup"` // Sets the Recursive Loop Protection for Lambda Function. // // It lets Lambda detect and terminate unintended recursive loops. // Default: RecursiveLoop.Terminate // RecursiveLoop awslambda.RecursiveLoop `field:"optional" json:"recursiveLoop" yaml:"recursiveLoop"` // The maximum of concurrent executions you want to reserve for the function. // See: https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html // // Default: - No specific limit - account limit. // ReservedConcurrentExecutions *float64 `field:"optional" json:"reservedConcurrentExecutions" yaml:"reservedConcurrentExecutions"` // Lambda execution role. // // This is the role that will be assumed by the function upon execution. // It controls the permissions that the function will have. The Role must // be assumable by the 'lambda.amazonaws.com' service principal. // // The default Role automatically has permissions granted for Lambda execution. If you // provide a Role, you must add the relevant AWS managed policies yourself. // // The relevant managed policies are "service-role/AWSLambdaBasicExecutionRole" and // "service-role/AWSLambdaVPCAccessExecutionRole". // Default: - A unique role will be generated for this lambda function. // Both supplied and generated roles can always be changed by calling `addToRolePolicy`. // Role awsiam.IRole `field:"optional" json:"role" yaml:"role"` // Sets the runtime management configuration for a function's version. // Default: Auto. // RuntimeManagementMode awslambda.RuntimeManagementMode `field:"optional" json:"runtimeManagementMode" yaml:"runtimeManagementMode"` // The list of security groups to associate with the Lambda's network interfaces. // // Only used if 'vpc' is supplied. // Default: - If the function is placed within a VPC and a security group is // not specified, either by this or securityGroup prop, a dedicated security // group will be created for this function. // SecurityGroups *[]awsec2.ISecurityGroup `field:"optional" json:"securityGroups" yaml:"securityGroups"` // Enable SnapStart for Lambda Function. // // SnapStart is currently supported for Java 11, Java 17, Python 3.12, Python 3.13, and .NET 8 runtime // Default: - No snapstart. // SnapStart awslambda.SnapStartConf `field:"optional" json:"snapStart" yaml:"snapStart"` // Sets the system log level for the function. // Default: "INFO". // // Deprecated: Use `systemLogLevelV2` as a property instead. SystemLogLevel *string `field:"optional" json:"systemLogLevel" yaml:"systemLogLevel"` // Sets the system log level for the function. // Default: SystemLogLevel.INFO // SystemLogLevelV2 awslambda.SystemLogLevel `field:"optional" json:"systemLogLevelV2" yaml:"systemLogLevelV2"` // The function execution time (in seconds) after which Lambda terminates the function. // // Because the execution time affects cost, set this value // based on the function's expected execution time. // Default: Duration.seconds(3) // Timeout awscdk.Duration `field:"optional" json:"timeout" yaml:"timeout"` // Enable AWS X-Ray Tracing for Lambda Function. // Default: Tracing.Disabled // Tracing awslambda.Tracing `field:"optional" json:"tracing" yaml:"tracing"` // VPC network to place Lambda network interfaces. // // Specify this if the Lambda function needs to access resources in a VPC. // This is required when `vpcSubnets` is specified. // Default: - Function is not placed within a VPC. // Vpc awsec2.IVpc `field:"optional" json:"vpc" yaml:"vpc"` // Where to place the network interfaces within the VPC. // // This requires `vpc` to be specified in order for interfaces to actually be // placed in the subnets. If `vpc` is not specify, this will raise an error. // // Note: Internet access for Lambda Functions requires a NAT Gateway, so picking // public subnets is not allowed (unless `allowPublicSubnet` is set to `true`). // Default: - the Vpc default strategy if not specified. // VpcSubnets *awsec2.SubnetSelection `field:"optional" json:"vpcSubnets" yaml:"vpcSubnets"` // The `AWS_NODEJS_CONNECTION_REUSE_ENABLED` environment variable does not exist in the AWS SDK for JavaScript v3. // // This prop will be deprecated when the Lambda Node16 runtime is deprecated on June 12, 2024. // See https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtime-support-policy // // Info for Node 16 runtimes / SDK v2 users: // // Whether to automatically reuse TCP connections when working with the AWS // SDK for JavaScript v2. // // This sets the `AWS_NODEJS_CONNECTION_REUSE_ENABLED` environment variable // to `1`. // See: https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-reusing-connections.html // // Default: - false (obsolete) for runtimes >= Node 18, true for runtimes <= Node 16. // AwsSdkConnectionReuse *bool `field:"optional" json:"awsSdkConnectionReuse" yaml:"awsSdkConnectionReuse"` // Bundling options. // Default: - use default bundling options: no minify, no sourcemap, all // modules are bundled. // Bundling *BundlingOptions `field:"optional" json:"bundling" yaml:"bundling"` // The code that will be deployed to the Lambda Handler. // // If included, then properties related to // bundling of the code are ignored. // // * If the `code` field is specified, then you must include the `handler` property. // Default: - the code is bundled by esbuild. // Code awslambda.Code `field:"optional" json:"code" yaml:"code"` // The path to the dependencies lock file (`yarn.lock`, `pnpm-lock.yaml`, `bun.lockb` or `package-lock.json`). // // This will be used as the source for the volume mounted in the Docker // container. // // Modules specified in `nodeModules` will be installed using the right // installer (`yarn`, `pnpm`, `bun` or `npm`) along with this lock file. // Default: - the path is found by walking up parent directories searching for // a `yarn.lock`, `pnpm-lock.yaml`, `bun.lockb` or `package-lock.json` file // DepsLockFilePath *string `field:"optional" json:"depsLockFilePath" yaml:"depsLockFilePath"` // Path to the entry file (JavaScript or TypeScript). // Default: - Derived from the name of the defining file and the construct's id. // If the `NodejsFunction` is defined in `stack.ts` with `my-handler` as id // (`new NodejsFunction(this, 'my-handler')`), the construct will look at `stack.my-handler.ts` // and `stack.my-handler.js`. // Entry *string `field:"optional" json:"entry" yaml:"entry"` // The name of the exported handler in the entry file. // // * If the `code` property is supplied, then you must include the `handler` property. The handler should be the name of the file // that contains the exported handler and the function that should be called when the AWS Lambda is invoked. For example, if // you had a file called `myLambda.js` and the function to be invoked was `myHandler`, then you should input `handler` property as `myLambda.myHandler`. // // * If the `code` property is not supplied and the handler input does not contain a `.`, then the handler is prefixed with `index.` (index period). Otherwise, // the handler property is not modified. // Default: handler. // Handler *string `field:"optional" json:"handler" yaml:"handler"` // The path to the directory containing project config files (`package.json` or `tsconfig.json`). // Default: - the directory containing the `depsLockFilePath`. // ProjectRoot *string `field:"optional" json:"projectRoot" yaml:"projectRoot"` // The runtime environment. // // Only runtimes of the Node.js family are // supported. // Default: `Runtime.NODEJS_LATEST` if the `@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion` feature flag is enabled, otherwise `Runtime.NODEJS_16_X` // Runtime awslambda.Runtime `field:"optional" json:"runtime" yaml:"runtime"` }
Properties for a NodejsFunction.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ Network: jsii.String("host"), SecurityOpt: jsii.String("no-new-privileges"), User: jsii.String("user:group"), VolumesFrom: []*string{ jsii.String("777f7dc92da7"), }, Volumes: []dockerVolume{ &dockerVolume{ HostPath: jsii.String("/host-path"), ContainerPath: jsii.String("/container-path"), }, }, }, })
type OutputFormat ¶ added in v2.7.0
type OutputFormat string
Output format for the generated JavaScript files.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ Minify: jsii.Boolean(true), // minify code, defaults to false SourceMap: jsii.Boolean(true), // include source map, defaults to false SourceMapMode: nodejs.SourceMapMode_INLINE, // defaults to SourceMapMode.DEFAULT SourcesContent: jsii.Boolean(false), // do not include original source into source map, defaults to true Target: jsii.String("es2020"), // target environment for the generated JavaScript code Loader: map[string]*string{ // Use the 'dataurl' loader for '.png' files ".png": jsii.String("dataurl"), }, Define: map[string]*string{ // Replace strings during build time "process.env.API_KEY": JSON.stringify(jsii.String("xxx-xxxx-xxx")), "process.env.PRODUCTION": JSON.stringify(jsii.Boolean(true)), "process.env.NUMBER": JSON.stringify(jsii.Number(123)), }, LogLevel: nodejs.LogLevel_ERROR, // defaults to LogLevel.WARNING KeepNames: jsii.Boolean(true), // defaults to false Tsconfig: jsii.String("custom-tsconfig.json"), // use custom-tsconfig.json instead of default, Metafile: jsii.Boolean(true), // include meta file, defaults to false Banner: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Footer: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Charset: nodejs.Charset_UTF8, // do not escape non-ASCII characters, defaults to Charset.ASCII Format: nodejs.OutputFormat_ESM, // ECMAScript module output format, defaults to OutputFormat.CJS (OutputFormat.ESM requires Node.js >= 14) MainFields: []*string{ jsii.String("module"), jsii.String("main"), }, // prefer ECMAScript versions of dependencies Inject: []*string{ jsii.String("./my-shim.js"), jsii.String("./other-shim.js"), }, // allows to automatically replace a global variable with an import from another file EsbuildArgs: map[string]interface{}{ // Pass additional arguments to esbuild "--log-limit": jsii.String("0"), "--splitting": jsii.Boolean(true), }, }, })
const ( // CommonJS. OutputFormat_CJS OutputFormat = "CJS" // ECMAScript module. // // Requires a running environment that supports `import` and `export` syntax. OutputFormat_ESM OutputFormat = "ESM" )
type SourceMapMode ¶
type SourceMapMode string
SourceMap mode for esbuild.
Example:
nodejs.NewNodejsFunction(this, jsii.String("my-handler"), &NodejsFunctionProps{ Bundling: &BundlingOptions{ Minify: jsii.Boolean(true), // minify code, defaults to false SourceMap: jsii.Boolean(true), // include source map, defaults to false SourceMapMode: nodejs.SourceMapMode_INLINE, // defaults to SourceMapMode.DEFAULT SourcesContent: jsii.Boolean(false), // do not include original source into source map, defaults to true Target: jsii.String("es2020"), // target environment for the generated JavaScript code Loader: map[string]*string{ // Use the 'dataurl' loader for '.png' files ".png": jsii.String("dataurl"), }, Define: map[string]*string{ // Replace strings during build time "process.env.API_KEY": JSON.stringify(jsii.String("xxx-xxxx-xxx")), "process.env.PRODUCTION": JSON.stringify(jsii.Boolean(true)), "process.env.NUMBER": JSON.stringify(jsii.Number(123)), }, LogLevel: nodejs.LogLevel_ERROR, // defaults to LogLevel.WARNING KeepNames: jsii.Boolean(true), // defaults to false Tsconfig: jsii.String("custom-tsconfig.json"), // use custom-tsconfig.json instead of default, Metafile: jsii.Boolean(true), // include meta file, defaults to false Banner: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Footer: jsii.String("/* comments */"), // requires esbuild >= 0.9.0, defaults to none Charset: nodejs.Charset_UTF8, // do not escape non-ASCII characters, defaults to Charset.ASCII Format: nodejs.OutputFormat_ESM, // ECMAScript module output format, defaults to OutputFormat.CJS (OutputFormat.ESM requires Node.js >= 14) MainFields: []*string{ jsii.String("module"), jsii.String("main"), }, // prefer ECMAScript versions of dependencies Inject: []*string{ jsii.String("./my-shim.js"), jsii.String("./other-shim.js"), }, // allows to automatically replace a global variable with an import from another file EsbuildArgs: map[string]interface{}{ // Pass additional arguments to esbuild "--log-limit": jsii.String("0"), "--splitting": jsii.Boolean(true), }, }, })
See: https://esbuild.github.io/api/#sourcemap
const ( // Default sourceMap mode - will generate a .js.map file alongside any generated .js file and add a special //# sourceMappingURL= comment to the bottom of the .js file pointing to the .js.map file. SourceMapMode_DEFAULT SourceMapMode = "DEFAULT" // External sourceMap mode - If you want to omit the special //# sourceMappingURL= comment from the generated .js file but you still want to generate the .js.map files. SourceMapMode_EXTERNAL SourceMapMode = "EXTERNAL" // Inline sourceMap mode - If you want to insert the entire source map into the .js file instead of generating a separate .js.map file. SourceMapMode_INLINE SourceMapMode = "INLINE" // Both sourceMap mode - If you want to have the effect of both inline and external simultaneously. SourceMapMode_BOTH SourceMapMode = "BOTH" )