SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
Architecture,
CreateFunctionCommand,
LambdaClient,
PackageType,
Runtime,
} from "@aws-sdk/client-lambda";
import { readFile } from "node:fs/promises";
import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js";
const dirname = dirnameFromMetaUrl(import.meta.url);
2022-09-19 14:05:31 -04:00
/** snippet-start:[javascript.v3.lambda.actions.CreateFunction] */
const createFunction = async (funcName, roleArn) => {
const client = new LambdaClient({});
const code = await readFile(`${dirname}../functions/${funcName}.zip`);
const command = new CreateFunctionCommand({
Code: { ZipFile: code },
FunctionName: funcName,
Role: roleArn,
Architectures: [Architecture.arm64],
2022-09-27 09:18:01 -04:00
Handler: "index.handler", // Required when sending a .zip file
PackageType: PackageType.Zip, // Required when sending a .zip file
Runtime: Runtime.nodejs16x, // Required when sending a .zip file
});
return client.send(command);
};
2022-09-19 14:05:31 -04:00
/** snippet-end:[javascript.v3.lambda.actions.CreateFunction] */
export { createFunction };