{"id":18107,"library":"amplify-category-function","title":"Amplify CLI Function Plugin","description":"The @aws-amplify/amplify-category-function package is an official Amplify CLI plugin for managing AWS Lambda functions within an Amplify project. It provides commands to add, build, push, and remove function resources, leveraging AWS CloudFormation for infrastructure as code. The current stable version is 5.8.0 (part of Amplify CLI v14.3.0). It requires the Amplify CLI environment and is typically used via the `amplify` command-line interface. Key differentiators: tight integration with Amplify's backend management, automatic IAM role generation, and support for multiple runtimes. Compared to raw AWS SDK usage, it abstracts away CloudFormation templates and provides a guided CLI workflow.","status":"active","version":"4.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/aws-amplify/amplify-cli","tags":["javascript","amplify","aws","typescript"],"install":[{"cmd":"npm install amplify-category-function","lang":"bash","label":"npm"},{"cmd":"yarn add amplify-category-function","lang":"bash","label":"yarn"},{"cmd":"pnpm add amplify-category-function","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core Amplify CLI runtime required for plugin execution","package":"@aws-amplify/cli","optional":false}],"imports":[{"note":"ESM-only since version 5.0; CommonJS require is deprecated","wrong":"const add = require('@aws-amplify/amplify-category-function').add","symbol":"add","correct":"import { add } from '@aws-amplify/amplify-category-function'"},{"note":"Function name is 'build', not 'buildFunction'","wrong":"import { buildFunction } from '@aws-amplify/amplify-category-function'","symbol":"build","correct":"import { build } from '@aws-amplify/amplify-category-function'"},{"note":"Use 'push' for pushing function resources","wrong":"import { pushResources } from '@aws-amplify/amplify-category-function'","symbol":"push","correct":"import { push } from '@aws-amplify/amplify-category-function'"},{"note":"The exported symbol is 'remove'","wrong":"import { removeFunction } from '@aws-amplify/amplify-category-function'","symbol":"remove","correct":"import { remove } from '@aws-amplify/amplify-category-function'"}],"quickstart":{"code":"// Ensure you have an initialized Amplify project\nimport { add, build, push } from '@aws-amplify/amplify-category-function';\n\n// Add a new function (interactive or with options)\nawait add({\n  name: 'myFunction',\n  runtime: 'nodejs18.x',\n  handler: 'index.handler',\n  path: './amplify/backend/function/myFunction/src',\n  // optional: override default settings\n});\n\n// Build the function\nawait build();\n\n// Push to cloud\nawait push();\n\n// Remove\nimport { remove } from '@aws-amplify/amplify-category-function';\nawait remove({ name: 'myFunction' });","lang":"typescript","description":"Demonstrates how to add, build, push, and remove an AWS Lambda function using the plugin's ESM imports. Assumes an existing Amplify project."},"warnings":[{"fix":"Use ES module imports: `import { add } from '@aws-amplify/amplify-category-function'`.","message":"ESM-only from version 5.0 onwards; CommonJS require() will fail.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use the `add` function with options object instead of relying on CLI prompts.","message":"The `amplify function add` command with interactive prompts may be deprecated in future versions; prefer programmatic API.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Ensure the directory exists before calling `add`, or use the interactive CLI which creates it.","message":"The function resource name must match an existing directory in `amplify/backend/function/`; otherwise, `add` will fail.","severity":"gotcha","affected_versions":"*"},{"fix":"Update code to handle pagination with smaller page size.","message":"In version 5.8.0, the MaxResults parameter for function listing was reduced from 50 to 10, which may affect scripts that iterate over functions.","severity":"breaking","affected_versions":"5.8.0"},{"fix":"For non-Node.js runtimes, use external build tools and ensure the output is placed in the source directory.","message":"The `build` command only builds Node.js functions; other runtimes (Python, Go) require manual build steps.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install @aws-amplify/amplify-category-function` or ensure it's added to your Amplify project.","cause":"Package not installed or not in `node_modules`.","error":"Cannot find module '@aws-amplify/amplify-category-function'"},{"fix":"Change to `import { add } from '@aws-amplify/amplify-category-function'`.","cause":"Using CommonJS `require` with ESM-only package.","error":"add is not a function"},{"fix":"Use a different name, or remove the existing function first with `remove`.","cause":"Attempting to add a function with a name that already exists in `amplify/backend/function/`.","error":"The function 'myFunction' already exists in the project."},{"fix":"Ensure the specified path contains a handler file (e.g., index.js) with the correct export.","cause":"The function source directory is missing a valid handler file.","error":"Cannot read property 'handler' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}