io.github.cdklabs.projen.awscdk.LambdaFunction Maven / Gradle / Ivy
Show all versions of projen Show documentation
package io.github.cdklabs.projen.awscdk;
/**
* (experimental) Generates a pre-bundled AWS Lambda function construct from handler code.
*
* To use this, create an AWS Lambda handler file under your source tree with
* the .lambda.ts
extension and add a LambdaFunction
component to your
* typescript project pointing to this entrypoint.
*
* This will add a task to your "compile" step which will use esbuild
to
* bundle the handler code into the build directory. It will also generate a
* file src/foo-function.ts
with a custom AWS construct called FooFunction
* which extends @aws-cdk/aws-lambda.Function
which is bound to the bundled
* handle through an asset.
*
* Example:
*
*
* new LambdaFunction(myProject, {
* srcdir: myProject.srcdir,
* entrypoint: 'src/foo.lambda.ts',
* });
*
*/
@javax.annotation.Generated(value = "jsii-pacmak/1.105.0 (build 0a2adcb)", date = "2024-11-15T17:03:55.027Z")
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@software.amazon.jsii.Jsii(module = io.github.cdklabs.projen.$Module.class, fqn = "projen.awscdk.LambdaFunction")
public class LambdaFunction extends io.github.cdklabs.projen.Component {
protected LambdaFunction(final software.amazon.jsii.JsiiObjectRef objRef) {
super(objRef);
}
protected LambdaFunction(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) {
super(initializationMode);
}
/**
* (experimental) Defines a pre-bundled AWS Lambda function construct from handler code.
*
* @param project The project to use. This parameter is required.
* @param options Options. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public LambdaFunction(final @org.jetbrains.annotations.NotNull io.github.cdklabs.projen.Project project, final @org.jetbrains.annotations.NotNull io.github.cdklabs.projen.awscdk.LambdaFunctionOptions options) {
super(software.amazon.jsii.JsiiObject.InitializationMode.JSII);
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { java.util.Objects.requireNonNull(project, "project is required"), java.util.Objects.requireNonNull(options, "options is required") });
}
/**
* (experimental) A fluent builder for {@link io.github.cdklabs.projen.awscdk.LambdaFunction}.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public static final class Builder implements software.amazon.jsii.Builder {
/**
* @return a new instance of {@link Builder}.
* @param project The project to use. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public static Builder create(final io.github.cdklabs.projen.Project project) {
return new Builder(project);
}
private final io.github.cdklabs.projen.Project project;
private final io.github.cdklabs.projen.awscdk.LambdaFunctionOptions.Builder options;
private Builder(final io.github.cdklabs.projen.Project project) {
this.project = project;
this.options = new io.github.cdklabs.projen.awscdk.LambdaFunctionOptions.Builder();
}
/**
* (experimental) Whether to automatically reuse TCP connections when working with the AWS SDK for JavaScript.
*
* This sets the AWS_NODEJS_CONNECTION_REUSE_ENABLED
environment variable
* to 1
.
*
* Not applicable when edgeLambda
is set to true
because environment
* variables are not supported in Lambda@Edge.
*
* Default: true
*
* @return {@code this}
* @see https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html
* @param awsSdkConnectionReuse Whether to automatically reuse TCP connections when working with the AWS SDK for JavaScript. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder awsSdkConnectionReuse(final java.lang.Boolean awsSdkConnectionReuse) {
this.options.awsSdkConnectionReuse(awsSdkConnectionReuse);
return this;
}
/**
* (experimental) Bundling options for this AWS Lambda function.
*
* If not specified the default bundling options specified for the project
* Bundler
instance will be used.
*
* Default: - defaults
*
* @return {@code this}
* @param bundlingOptions Bundling options for this AWS Lambda function. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder bundlingOptions(final io.github.cdklabs.projen.javascript.BundlingOptions bundlingOptions) {
this.options.bundlingOptions(bundlingOptions);
return this;
}
/**
* (experimental) Whether to create a cloudfront.experimental.EdgeFunction
instead of a lambda.Function
.
*
* Default: false
*
* @return {@code this}
* @param edgeLambda Whether to create a cloudfront.experimental.EdgeFunction
instead of a lambda.Function
. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder edgeLambda(final java.lang.Boolean edgeLambda) {
this.options.edgeLambda(edgeLambda);
return this;
}
/**
* (experimental) The node.js version to target.
*
* Default: Runtime.NODEJS_18_X
*
* @return {@code this}
* @param runtime The node.js version to target. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder runtime(final io.github.cdklabs.projen.awscdk.LambdaRuntime runtime) {
this.options.runtime(runtime);
return this;
}
/**
* (experimental) AWS CDK dependency manager.
*
* @return {@code this}
* @param cdkDeps AWS CDK dependency manager. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder cdkDeps(final io.github.cdklabs.projen.awscdk.AwsCdkDeps cdkDeps) {
this.options.cdkDeps(cdkDeps);
return this;
}
/**
* (experimental) A path from the project root directory to a TypeScript file which contains the AWS Lambda handler entrypoint (exports a handler
function).
*
* This is relative to the root directory of the project.
*
* Example:
*
*
* "src/subdir/foo.lambda.ts"
*
*
* @return {@code this}
* @param entrypoint A path from the project root directory to a TypeScript file which contains the AWS Lambda handler entrypoint (exports a handler
function). This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder entrypoint(final java.lang.String entrypoint) {
this.options.entrypoint(entrypoint);
return this;
}
/**
* (experimental) The name of the generated TypeScript source file.
*
* This file should also be
* under the source tree.
*
* Default: - The name of the entrypoint file, with the `-function.ts` suffix
* instead of `.lambda.ts`.
*
* @return {@code this}
* @param constructFile The name of the generated TypeScript source file. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder constructFile(final java.lang.String constructFile) {
this.options.constructFile(constructFile);
return this;
}
/**
* (experimental) The name of the generated lambda.Function
subclass.
*
* Default: - A pascal cased version of the name of the entrypoint file, with
* the extension `Function` (e.g. `ResizeImageFunction`).
*
* @return {@code this}
* @param constructName The name of the generated lambda.Function
subclass. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder constructName(final java.lang.String constructName) {
this.options.constructName(constructName);
return this;
}
/**
* @return a newly built instance of {@link io.github.cdklabs.projen.awscdk.LambdaFunction}.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@Override
public io.github.cdklabs.projen.awscdk.LambdaFunction build() {
return new io.github.cdklabs.projen.awscdk.LambdaFunction(
this.project,
this.options.build()
);
}
}
}