UNPKG

@pulumi/aws-native

Version:

The Pulumi AWS Cloud Control Provider enables you to build, deploy, and manage [any AWS resource that's supported by the AWS Cloud Control API](https://github.com/pulumi/pulumi-aws-native/blob/master/provider/cmd/pulumi-gen-aws-native/supported-types.txt)

340 lines • 16.2 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Function = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * The ``AWS::Lambda::Function`` resource creates a Lambda function. To create a function, you need a [deployment package](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html) and an [execution role](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html). The deployment package is a .zip file archive or container image that contains your function code. The execution role grants the function permission to use AWS services, such as Amazon CloudWatch Logs for log streaming and AWS X-Ray for request tracing. * You set the package type to ``Image`` if the deployment package is a [container image](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html). For these functions, include the URI of the container image in the ECR registry in the [ImageUri property of the Code property](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-imageuri). You do not need to specify the handler and runtime properties. * You set the package type to ``Zip`` if the deployment package is a [.zip file archive](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html#gettingstarted-package-zip). For these functions, specify the S3 location of your .zip file in the ``Code`` property. Alternatively, for Node.js and Python functions, you can define your function inline in the [ZipFile property of the Code property](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-zipfile). In both cases, you must also specify the handler and runtime properties. * You can use [code signing](https://docs.aws.amazon.com/lambda/latest/dg/configuration-codesigning.html) if your deployment package is a .zip file archive. To enable code signing for this function, specify the ARN of a code-signing configuration. When a user attempts to deploy a code package with ``UpdateFunctionCode``, Lambda checks that the code package has a valid signature from a trusted publisher. The code-signing configuration includes a set of signing profiles, which define the trusted publishers for this function. * When you update a ``AWS::Lambda::Function`` resource, CFNshort calls the [UpdateFunctionConfiguration](https://docs.aws.amazon.com/lambda/latest/api/API_UpdateFunctionConfiguration.html) and [UpdateFunctionCode](https://docs.aws.amazon.com/lambda/latest/api/API_UpdateFunctionCode.html)LAM APIs under the hood. Because these calls happen sequentially, and invocations can happen between these calls, your function may encounter errors in the time between the calls. For example, if you remove an environment variable, and the code that references that environment variable in the same CFNshort update, you may see invocation errors related to a missing environment variable. To work around this, you can invoke your function against a version or alias by default, rather than the ``$LATEST`` version. * Note that you configure [provisioned concurrency](https://docs.aws.amazon.com/lambda/latest/dg/provisioned-concurrency.html) on a ``AWS::Lambda::Version`` or a ``AWS::Lambda::Alias``. * For a complete introduction to Lambda functions, see [What is Lambda?](https://docs.aws.amazon.com/lambda/latest/dg/lambda-welcome.html) in the *Lambda developer guide.* * * ## Example Usage * ### Example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws_native from "@pulumi/aws-native"; * * const _function = new aws_native.lambda.Function("function", { * handler: "index.handler", * role: "arn:aws:iam::123456789012:role/lambda-role", * code: { * zipFile: `exports.handler = function(event){ * console.log(JSON.stringify(event, null, 2)) * const response = { * statusCode: 200, * body: JSON.stringify('Hello from Lambda!') * } * return response * }; * `, * }, * runtime: "nodejs18.x", * tracingConfig: { * mode: aws_native.lambda.FunctionTracingConfigMode.Active, * }, * }); * const version = new aws_native.lambda.Version("version", { * functionName: _function.id, * description: "v1", * }); * const alias = new aws_native.lambda.Alias("alias", { * functionName: _function.id, * functionVersion: version.version, * name: "BLUE", * }); * * ``` * ### Example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws_native from "@pulumi/aws-native"; * * const _function = new aws_native.lambda.Function("function", { * handler: "index.handler", * role: "arn:aws:iam::123456789012:role/lambda-role", * code: { * zipFile: `exports.handler = function(event){ * console.log(JSON.stringify(event, null, 2)) * const response = { * statusCode: 200, * body: JSON.stringify('Hello again from Lambda!') * } * return response * } * `, * }, * runtime: "nodejs18.x", * tracingConfig: { * mode: aws_native.lambda.FunctionTracingConfigMode.Active, * }, * }); * const version = new aws_native.lambda.Version("version", { * functionName: _function.id, * description: "v1", * }); * const newVersion = new aws_native.lambda.Version("newVersion", { * functionName: _function.id, * description: "v2", * }); * const alias = new aws_native.lambda.Alias("alias", { * functionName: _function.id, * functionVersion: newVersion.version, * name: "BLUE", * routingConfig: { * additionalVersionWeights: [{ * functionVersion: version.version, * functionWeight: 0.5, * }], * }, * }); * * ``` * ### Example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws_native from "@pulumi/aws-native"; * * const _function = new aws_native.lambda.Function("function", { * handler: "index.handler", * role: "arn:aws:iam::123456789012:role/lambda-role", * code: { * zipFile: `exports.handler = async (event) => { * console.log(JSON.stringify(event, null, 2)); * const response = { * statusCode: 200, * body: JSON.stringify('Hello from Lambda!'), * }; * return response; * }; * `, * }, * runtime: "nodejs18.x", * tracingConfig: { * mode: aws_native.lambda.FunctionTracingConfigMode.Active, * }, * }); * const version = new aws_native.lambda.Version("version", {functionName: _function.id}); * const asyncconfig = new aws_native.lambda.EventInvokeConfig("asyncconfig", { * destinationConfig: { * onFailure: { * destination: "arn:aws:sqs:us-east-2:123456789012:dlq", * }, * onSuccess: { * destination: "arn:aws:sqs:us-east-2:123456789012:dlq", * }, * }, * functionName: _function.id, * maximumEventAgeInSeconds: 300, * maximumRetryAttempts: 1, * qualifier: version.version, * }); * * ``` * ### Example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws_native from "@pulumi/aws-native"; * * const primer = new aws_native.lambda.Function("primer", { * runtime: "nodejs18.x", * role: "arn:aws:iam::123456789012:role/lambda-role", * handler: "index.handler", * code: { * zipFile: `const { S3Client, ListBucketsCommand } = require("@aws-sdk/client-s3"); * const s3 = new S3Client({ region: "us-east-1" }); // replace "us-east-1" with your AWS region * * exports.handler = async function(event) { * const command = new ListBucketsCommand({}); * const response = await s3.send(command); * return response.Buckets; * }; * `, * }, * description: "List Amazon S3 buckets in us-east-1.", * tracingConfig: { * mode: aws_native.lambda.FunctionTracingConfigMode.Active, * }, * }); * * ``` * ### Example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws_native from "@pulumi/aws-native"; * * const _function = new aws_native.lambda.Function("function", { * handler: "index.handler", * role: "arn:aws:iam::123456789012:role/lambda-role", * code: { * s3Bucket: "my-bucket", * s3Key: "function.zip", * }, * runtime: "nodejs18.x", * timeout: 5, * tracingConfig: { * mode: aws_native.lambda.FunctionTracingConfigMode.Active, * }, * vpcConfig: { * securityGroupIds: ["sg-085912345678492fb"], * subnetIds: [ * "subnet-071f712345678e7c8", * "subnet-07fd123456788a036", * ], * }, * }); * * ``` * ### Example * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws_native from "@pulumi/aws-native"; * * const _function = new aws_native.lambda.Function("function", { * handler: "index.handler", * role: "arn:aws:iam::123456789012:role/lambda-role", * code: { * zipFile: `exports.handler = async (event) => { * console.log(JSON.stringify(event, null, 2)); * const response = { * statusCode: 200, * body: JSON.stringify('Hello from Lambda!'), * }; * return response; * }; * `, * }, * runtime: "nodejs18.x", * tracingConfig: { * mode: aws_native.lambda.FunctionTracingConfigMode.Active, * }, * }); * const version = new aws_native.lambda.Version("version", { * functionName: _function.id, * description: "v1", * provisionedConcurrencyConfig: { * provisionedConcurrentExecutions: 20, * }, * }); * * ``` */ class Function extends pulumi.CustomResource { /** * Get an existing Function resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, opts) { return new Function(name, undefined, Object.assign(Object.assign({}, opts), { id: id })); } /** * Returns true if the given object is an instance of Function. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === Function.__pulumiType; } /** * Create a Function resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name, args, opts) { let resourceInputs = {}; opts = opts || {}; if (!opts.id) { if ((!args || args.code === undefined) && !opts.urn) { throw new Error("Missing required property 'code'"); } if ((!args || args.role === undefined) && !opts.urn) { throw new Error("Missing required property 'role'"); } resourceInputs["architectures"] = args ? args.architectures : undefined; resourceInputs["code"] = args ? args.code : undefined; resourceInputs["codeSigningConfigArn"] = args ? args.codeSigningConfigArn : undefined; resourceInputs["deadLetterConfig"] = args ? args.deadLetterConfig : undefined; resourceInputs["description"] = args ? args.description : undefined; resourceInputs["environment"] = args ? args.environment : undefined; resourceInputs["ephemeralStorage"] = args ? args.ephemeralStorage : undefined; resourceInputs["fileSystemConfigs"] = args ? args.fileSystemConfigs : undefined; resourceInputs["functionName"] = args ? args.functionName : undefined; resourceInputs["handler"] = args ? args.handler : undefined; resourceInputs["imageConfig"] = args ? args.imageConfig : undefined; resourceInputs["kmsKeyArn"] = args ? args.kmsKeyArn : undefined; resourceInputs["layers"] = args ? args.layers : undefined; resourceInputs["loggingConfig"] = args ? args.loggingConfig : undefined; resourceInputs["memorySize"] = args ? args.memorySize : undefined; resourceInputs["packageType"] = args ? args.packageType : undefined; resourceInputs["recursiveLoop"] = args ? args.recursiveLoop : undefined; resourceInputs["reservedConcurrentExecutions"] = args ? args.reservedConcurrentExecutions : undefined; resourceInputs["role"] = args ? args.role : undefined; resourceInputs["runtime"] = args ? args.runtime : undefined; resourceInputs["runtimeManagementConfig"] = args ? args.runtimeManagementConfig : undefined; resourceInputs["snapStart"] = args ? args.snapStart : undefined; resourceInputs["tags"] = args ? args.tags : undefined; resourceInputs["timeout"] = args ? args.timeout : undefined; resourceInputs["tracingConfig"] = args ? args.tracingConfig : undefined; resourceInputs["vpcConfig"] = args ? args.vpcConfig : undefined; resourceInputs["arn"] = undefined /*out*/; resourceInputs["snapStartResponse"] = undefined /*out*/; } else { resourceInputs["architectures"] = undefined /*out*/; resourceInputs["arn"] = undefined /*out*/; resourceInputs["code"] = undefined /*out*/; resourceInputs["codeSigningConfigArn"] = undefined /*out*/; resourceInputs["deadLetterConfig"] = undefined /*out*/; resourceInputs["description"] = undefined /*out*/; resourceInputs["environment"] = undefined /*out*/; resourceInputs["ephemeralStorage"] = undefined /*out*/; resourceInputs["fileSystemConfigs"] = undefined /*out*/; resourceInputs["functionName"] = undefined /*out*/; resourceInputs["handler"] = undefined /*out*/; resourceInputs["imageConfig"] = undefined /*out*/; resourceInputs["kmsKeyArn"] = undefined /*out*/; resourceInputs["layers"] = undefined /*out*/; resourceInputs["loggingConfig"] = undefined /*out*/; resourceInputs["memorySize"] = undefined /*out*/; resourceInputs["packageType"] = undefined /*out*/; resourceInputs["recursiveLoop"] = undefined /*out*/; resourceInputs["reservedConcurrentExecutions"] = undefined /*out*/; resourceInputs["role"] = undefined /*out*/; resourceInputs["runtime"] = undefined /*out*/; resourceInputs["runtimeManagementConfig"] = undefined /*out*/; resourceInputs["snapStart"] = undefined /*out*/; resourceInputs["snapStartResponse"] = undefined /*out*/; resourceInputs["tags"] = undefined /*out*/; resourceInputs["timeout"] = undefined /*out*/; resourceInputs["tracingConfig"] = undefined /*out*/; resourceInputs["vpcConfig"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const replaceOnChanges = { replaceOnChanges: ["functionName", "packageType"] }; opts = pulumi.mergeOptions(opts, replaceOnChanges); super(Function.__pulumiType, name, resourceInputs, opts); } } exports.Function = Function; /** @internal */ Function.__pulumiType = 'aws-native:lambda:Function'; //# sourceMappingURL=function.js.map