From 63f71b50561e75b308301247e9a023cae6873e65 Mon Sep 17 00:00:00 2001 From: Burak Karahan Date: Mon, 23 Dec 2024 00:05:53 +0300 Subject: [PATCH 1/7] feature(function): add custom functions documentation for AWS Amplify Gen 2 @aws-amplify/amplify-backend/1602 --- cspell.json | 17 +- src/directory/directory.mjs | 3 + .../functions/custom-functions/index.mdx | 220 ++++++++++++++++++ 3 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx diff --git a/cspell.json b/cspell.json index 49baa6ee1e1..1a8cb5adc24 100644 --- a/cspell.json +++ b/cspell.json @@ -1618,14 +1618,25 @@ "knowledgebases", "rehype", "assetlinks", - "AMPLIFYRULES" + "AMPLIFYRULES", + "manylinux", + "GOARCH", + "norpc" + ], + "flagWords": [ + "hte", + "full-stack", + "Full-stack", + "Full-Stack", + "sudo" ], - "flagWords": ["hte", "full-stack", "Full-stack", "Full-Stack", "sudo"], "patterns": [ { "name": "youtube-embed-ids", "pattern": "/embedId=\".*\" /" } ], - "ignoreRegExpList": ["youtube-embed-ids"] + "ignoreRegExpList": [ + "youtube-embed-ids" + ] } diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index 269af6f34ad..37a3797af95 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -448,6 +448,9 @@ export const directory = { }, { path: 'src/pages/[platform]/build-a-backend/functions/modify-resources-with-cdk/index.mdx' + }, + { + path: 'src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx' } ] }, diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx new file mode 100644 index 00000000000..e5a6e44f9a2 --- /dev/null +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -0,0 +1,220 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Custom functions', + description: + 'Use another AWS Lambda runtimes like python, golang to perform tasks and customize workflows.', + platforms: [ + 'android', + 'angular', + 'flutter', + 'javascript', + 'nextjs', + 'react', + 'react-native', + 'swift', + 'vue' + ] +}; + +export function getStaticPaths() { + return getCustomStaticPath(meta.platforms); +} + +export function getStaticProps(context) { + return { + props: { + platform: context.params.platform, + meta + } + }; +} + +AWS Amplify Gen 2 Functions are AWS Lambda functions that can be used to perform tasks and customize workflows in your Amplify app.Functions can be written in Node.js, Python, Go, or any other language supported by AWS Lambda: + + + +**Note:** Custom runtimes are not supported in Amplify Functions directly. If you need docker support to use a custom runtime for example in Python, Docker is not supported in Amplify Hosting and Amplify backend auto build. You shouldn't use docker build in your function.There is an example of how to use python in a lambda function in the without Docker section below. + + + +Technically, you can use any language supported by AWS Lambda. These are NodeJS, Python, Java, .NET, Ruby. +To use other languages in Lambda, such as Go or Rust, use an OS-only runtime. + +In this guide, you will learn how to create python and golang functions in Amplify Functions. + +# Python functions +To get started, create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the Function with `defineFunction`: + +```ts title="amplify/functions/say-hello/resource.ts" +import { defineFunction } from "@aws-amplify/backend"; +import { DockerImage, Duration } from "aws-cdk-lib"; +import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; +import { execSync } from "child_process"; +import * as path from "path"; + +export const sayHello = defineFunction( + (scope) => + new Function(scope, "say-hello", { + handler: "index.handler", + runtime: Runtime.PYTHON_3_9, // or any other python version + timeout: Duration.seconds(20), // default is 3 seconds + code: Code.fromAsset(functionDir, { + bundling: { + image: DockerImage.fromRegistry("dummy"), + local: { + tryBundle(outputDir: string) { + execSync( + `python3 -m pip install -r ${path.join(functionDir, "requirements.txt")} -t ${path.join(outputDir)} --platform manylinux2014_x86_64 --only-binary=:all:` + ); + execSync(`rsync -rLv ${functionDir}/* ${path.join(outputDir)}`); + return true; + }, + }, + }, + }), + }) +); +``` + +Next, create the corresponding handler file at `amplify/functions/say-hello/handler.ts`. This is where your function code will go. + +```ts title="amplify/functions/say-hello/index.py" +import json + +def handler(event, context): + return { + "statusCode": 200, + "body": json.dumps({ + "message": "Hello World", + }), + } +``` + +The handler file _must_ export a function named "handler". This is the entry point to your function. For more information on writing functions, refer to the [AWS documentation for Lambda function handlers using python](https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html). + +If you need python packages, you can add them to a `requirements.txt` file in the same directory as your handler file. The `bundling` option in the `Code.fromAsset` method will install these packages for you. +Create a `requirements.txt` file in the same directory as your handler file. This file should contain the names of the packages you want to install. For example: + +```txt title="amplify/functions/say-hello/requirements.txt" +request==2.25.1 +some-other-package>=1.0.0 +``` + +You're now ready to deploy your python function. Next is the same process as the Node.js/TypeScript function. Go to [Common steps for all languages](#common-steps-for-all-languages) to continue. + +# Go functions +To get started, install go package from npm. go to your backend directory, you should see amplify folder inside it. and run the following command: +```npm i @aws-cdk/aws-lambda-go-alpha``` + + create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the Function with `defineFunction`: + +```ts title="amplify/functions/say-hello/resource.ts" +import { defineFunction } from "@aws-amplify/backend"; +import { GoFunction } from "@aws-cdk/aws-lambda-go-alpha"; +import { Runtime } from "aws-cdk-lib/aws-lambda"; + +export const sendSmsGoFunctionHandler = defineFunction((scope) => { + return new GoFunction(scope, "say-hello", { + entry: "./amplify/function/say-hello/", + runtime: Runtime.PROVIDED_AL2023, + environment: { + GOARCH: "amd64", + }, + bundling: { + goBuildFlags: ["-tags lambda.norpc"], + }, + }); +}); +``` + +Next, create the corresponding handler file at `amplify/functions/say-hello/main.go`. This is where your function code will go. + +```go title="amplify/functions/say-hello/main.go" +package main + +import ( + "context" + "fmt" + + "github.com/aws/aws-lambda-go/lambda" +) + +type Event struct { + Arguments Arguments `json:"arguments"` +} + +type Arguments struct { + Title string `json:"phone"` + Msg string `json:"msg"` +} + +func HandleRequest(ctx context.Context, event Event) (string, error) { + fmt.Println("Received event: ", event) + + // fmt.Println("Message sent to: ", event.Arguments.Msg) + // You can use lambda arguments in your code + + return "Hello World!", nil +} + +func main() { + lambda.Start(HandleRequest) +} +``` + +Then you should run the following command to build the go function: +```bash title="terminal" +go mod init lambda +``` +then run to install the dependencies. + +```bash title="terminal" +go mod tidy +``` + +You're now ready to deploy your golang function. Next is the same process as the Node.js/TypeScript function. + +# Common steps for all languages +Lastly, this function needs to be added to your backend. + +```ts title="amplify/backend.ts" +import { defineBackend } from '@aws-amplify/backend'; +// highlight-next-line +import { sayHello } from './functions/say-hello/resource'; + +defineBackend({ + // highlight-next-line + sayHello +}); +``` + +Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your Function. + +To invoke your Function, we recommend adding your [Function as a handler for a custom query with your Amplify Data resource](/[platform]/build-a-backend/data/custom-business-logic/). This will enable you to strongly type Function arguments and the return statement, and use this to author your Function's business logic. To get started, open your `amplify/data/resource.ts` file and specify a new query in your schema: + +```ts title="amplify/data/resource.ts" +import { type ClientSchema, a, defineData } from "@aws-amplify/backend" +import { sayHello } from "../functions/say-hello/resource" + +const schema = a.schema({ + // highlight-start + sayHello: a + .query() + .arguments({ + name: a.string(), + }) + .returns(a.string()) + .handler(a.handler.function(sayHello)), + // highlight-end +}) + +export type Schema = ClientSchema + +export const data = defineData({ + schema, + authorizationModes: { + defaultAuthorizationMode: "iam", + }, +}) +``` From 03e2733a774feb80ca5ca62d1853bb6b77bb20a7 Mon Sep 17 00:00:00 2001 From: Burak Karahan Date: Thu, 2 Jan 2025 00:24:32 +0300 Subject: [PATCH 2/7] chore(function): rename function handler and update handler file path, remove go lambda alpha package --- .../functions/custom-functions/index.mdx | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx index e5a6e44f9a2..15475a45753 100644 --- a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -52,8 +52,11 @@ import { DockerImage, Duration } from "aws-cdk-lib"; import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; import { execSync } from "child_process"; import * as path from "path"; +import { fileURLToPath } from "url"; -export const sayHello = defineFunction( +const functionDir = path.dirname(fileURLToPath(import.meta.url)); + +export const sayHelloFunctionHandler = defineFunction( (scope) => new Function(scope, "say-hello", { handler: "index.handler", @@ -77,7 +80,7 @@ export const sayHello = defineFunction( ); ``` -Next, create the corresponding handler file at `amplify/functions/say-hello/handler.ts`. This is where your function code will go. +Next, create the corresponding handler file at `amplify/functions/say-hello/index.py`. This is where your function code will go. ```ts title="amplify/functions/say-hello/index.py" import json @@ -111,21 +114,36 @@ To get started, install go package from npm. go to your backend directory, you s ```ts title="amplify/functions/say-hello/resource.ts" import { defineFunction } from "@aws-amplify/backend"; -import { GoFunction } from "@aws-cdk/aws-lambda-go-alpha"; -import { Runtime } from "aws-cdk-lib/aws-lambda"; - -export const sendSmsGoFunctionHandler = defineFunction((scope) => { - return new GoFunction(scope, "say-hello", { - entry: "./amplify/function/say-hello/", - runtime: Runtime.PROVIDED_AL2023, - environment: { - GOARCH: "amd64", - }, - bundling: { - goBuildFlags: ["-tags lambda.norpc"], - }, - }); -}); +import { DockerImage, Duration } from "aws-cdk-lib"; +import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; +import { execSync } from "child_process"; +import * as path from "path"; +import { fileURLToPath } from "url"; + +const functionDir = path.dirname(fileURLToPath(import.meta.url)); + +export const sayHelloFunctionHandler = defineFunction( + (scope) => + new Function(scope, "say-hello", { + handler: "bootstrap", + runtime: Runtime.PROVIDED_AL2023, // or any other python version + timeout: Duration.seconds(3), // default is 3 seconds + code: Code.fromAsset(functionDir, { + bundling: { + image: DockerImage.fromRegistry("dummy"), + local: { + tryBundle(outputDir: string) { + execSync(`rsync -rLv ${functionDir}/* ${path.join(outputDir)}`); + execSync( + `cd ${path.join(outputDir)} && GOARCH=amd64 GOOS=linux go build -tags lambda.norpc -o ${path.join(outputDir)}/bootstrap ${functionDir}/main.go` + ); + return true; + }, + }, + }, + }), + }), +); ``` Next, create the corresponding handler file at `amplify/functions/say-hello/main.go`. This is where your function code will go. @@ -181,11 +199,11 @@ Lastly, this function needs to be added to your backend. ```ts title="amplify/backend.ts" import { defineBackend } from '@aws-amplify/backend'; // highlight-next-line -import { sayHello } from './functions/say-hello/resource'; +import { sayHelloFunctionHandler } from './functions/say-hello/resource'; defineBackend({ // highlight-next-line - sayHello + sayHelloFunctionHandler, }); ``` @@ -195,7 +213,7 @@ To invoke your Function, we recommend adding your [Function as a handler for a c ```ts title="amplify/data/resource.ts" import { type ClientSchema, a, defineData } from "@aws-amplify/backend" -import { sayHello } from "../functions/say-hello/resource" +import { sayHelloFunctionHandler } from "../functions/say-hello/resource" const schema = a.schema({ // highlight-start @@ -205,7 +223,7 @@ const schema = a.schema({ name: a.string(), }) .returns(a.string()) - .handler(a.handler.function(sayHello)), + .handler(a.handler.function(sayHelloFunctionHandler)), // highlight-end }) From 4b0242fd5a5bd78b51f0494a95783fbe5e41908c Mon Sep 17 00:00:00 2001 From: Burak Karahan Date: Tue, 7 Jan 2025 15:52:56 +0300 Subject: [PATCH 3/7] docs(functions): improve documentation for Python and Go functions, correcting capitalization and enhancing clarity --- .../functions/custom-functions/index.mdx | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx index 15475a45753..66117c8e1b7 100644 --- a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -3,7 +3,7 @@ import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; export const meta = { title: 'Custom functions', description: - 'Use another AWS Lambda runtimes like python, golang to perform tasks and customize workflows.', + 'Use another AWS Lambda runtimes like Python, Golang to perform tasks and customize workflows.', platforms: [ 'android', 'angular', @@ -30,29 +30,29 @@ export function getStaticProps(context) { }; } -AWS Amplify Gen 2 Functions are AWS Lambda functions that can be used to perform tasks and customize workflows in your Amplify app.Functions can be written in Node.js, Python, Go, or any other language supported by AWS Lambda: +AWS Amplify Gen 2 functions are AWS Lambda functions that can be used to perform tasks and customize workflows in your Amplify app. Functions can be written in Node.js, Python, Go, or any [other language supported by AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). -**Note:** Custom runtimes are not supported in Amplify Functions directly. If you need docker support to use a custom runtime for example in Python, Docker is not supported in Amplify Hosting and Amplify backend auto build. You shouldn't use docker build in your function.There is an example of how to use python in a lambda function in the without Docker section below. +**Note:** [Fullstack Git-based environments](https://docs.amplify.aws/react/how-amplify-works/concepts/#fullstack-git-based-environments) do not support Docker for functions bundling out of the box. Technically, you can use any language supported by AWS Lambda. These are NodeJS, Python, Java, .NET, Ruby. To use other languages in Lambda, such as Go or Rust, use an OS-only runtime. -In this guide, you will learn how to create python and golang functions in Amplify Functions. +In this guide, you will learn how to create Python and Go functions with Amplify functions. The examples shown in this guide do not use Docker to build functions. Instead, the examples use commands that run on your host system to build, and as such require the necessary tooling for the language you are using for your functions. -# Python functions -To get started, create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the Function with `defineFunction`: +## Python +To get started, create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the function with `defineFunction`: ```ts title="amplify/functions/say-hello/resource.ts" +import { execSync } from "node:child_process"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; import { defineFunction } from "@aws-amplify/backend"; import { DockerImage, Duration } from "aws-cdk-lib"; import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; -import { execSync } from "child_process"; -import * as path from "path"; -import { fileURLToPath } from "url"; const functionDir = path.dirname(fileURLToPath(import.meta.url)); @@ -94,9 +94,9 @@ def handler(event, context): } ``` -The handler file _must_ export a function named "handler". This is the entry point to your function. For more information on writing functions, refer to the [AWS documentation for Lambda function handlers using python](https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html). +The handler file _must_ export a function named "handler". This is the entry point to your function. For more information on writing functions, refer to the [AWS documentation for Lambda function handlers using Python](https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html). -If you need python packages, you can add them to a `requirements.txt` file in the same directory as your handler file. The `bundling` option in the `Code.fromAsset` method will install these packages for you. +If you need Python packages, you can add them to a `requirements.txt` file in the same directory as your handler file. The `bundling` option in the `Code.fromAsset` method will install these packages for you. Create a `requirements.txt` file in the same directory as your handler file. This file should contain the names of the packages you want to install. For example: ```txt title="amplify/functions/say-hello/requirements.txt" @@ -106,22 +106,19 @@ some-other-package>=1.0.0 You're now ready to deploy your python function. Next is the same process as the Node.js/TypeScript function. Go to [Common steps for all languages](#common-steps-for-all-languages) to continue. -# Go functions -To get started, install go package from npm. go to your backend directory, you should see amplify folder inside it. and run the following command: -```npm i @aws-cdk/aws-lambda-go-alpha``` - - create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the Function with `defineFunction`: +## Go +To get started, Create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the function with `defineFunction`: ```ts title="amplify/functions/say-hello/resource.ts" import { defineFunction } from "@aws-amplify/backend"; import { DockerImage, Duration } from "aws-cdk-lib"; import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; -import { execSync } from "child_process"; -import * as path from "path"; -import { fileURLToPath } from "url"; - -const functionDir = path.dirname(fileURLToPath(import.meta.url)); - +import { execSync } from "node:child_process"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import { defineFunction } from "@aws-amplify/backend"; +import { DockerImage, Duration } from "aws-cdk-lib"; +import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; export const sayHelloFunctionHandler = defineFunction( (scope) => new Function(scope, "say-hello", { @@ -182,22 +179,20 @@ func main() { ``` Then you should run the following command to build the go function: -```bash title="terminal" +```bash title="terminal" showLineNumbers={false} go mod init lambda ``` then run to install the dependencies. -```bash title="terminal" +```bash title="terminal" showLineNumbers={false} go mod tidy ``` You're now ready to deploy your golang function. Next is the same process as the Node.js/TypeScript function. -# Common steps for all languages -Lastly, this function needs to be added to your backend. +## Common steps for all languages -```ts title="amplify/backend.ts" -import { defineBackend } from '@aws-amplify/backend'; +Regardless of the language used, your function needs to be added to your backend. // highlight-next-line import { sayHelloFunctionHandler } from './functions/say-hello/resource'; @@ -212,7 +207,7 @@ Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will inclu To invoke your Function, we recommend adding your [Function as a handler for a custom query with your Amplify Data resource](/[platform]/build-a-backend/data/custom-business-logic/). This will enable you to strongly type Function arguments and the return statement, and use this to author your Function's business logic. To get started, open your `amplify/data/resource.ts` file and specify a new query in your schema: ```ts title="amplify/data/resource.ts" -import { type ClientSchema, a, defineData } from "@aws-amplify/backend" +Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your function. import { sayHelloFunctionHandler } from "../functions/say-hello/resource" const schema = a.schema({ From eb92ef50289db83c6a5233094d14f71cfcfcc255 Mon Sep 17 00:00:00 2001 From: Burak Karahan Date: Tue, 7 Jan 2025 21:53:02 +0300 Subject: [PATCH 4/7] docs(functions): clarify function invocation instructions and improve code examples in custom functions documentation --- .../functions/custom-functions/index.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx index 66117c8e1b7..41a6ec0516e 100644 --- a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -110,15 +110,15 @@ You're now ready to deploy your python function. Next is the same process as the To get started, Create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the function with `defineFunction`: ```ts title="amplify/functions/say-hello/resource.ts" -import { defineFunction } from "@aws-amplify/backend"; -import { DockerImage, Duration } from "aws-cdk-lib"; -import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; import { execSync } from "node:child_process"; import * as path from "node:path"; import { fileURLToPath } from "node:url"; import { defineFunction } from "@aws-amplify/backend"; import { DockerImage, Duration } from "aws-cdk-lib"; import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; +import { defineFunction } from "@aws-amplify/backend"; +import { DockerImage, Duration } from "aws-cdk-lib"; +import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda"; export const sayHelloFunctionHandler = defineFunction( (scope) => new Function(scope, "say-hello", { @@ -193,6 +193,7 @@ You're now ready to deploy your golang function. Next is the same process as the ## Common steps for all languages Regardless of the language used, your function needs to be added to your backend. +```ts title="amplify/backend.ts" // highlight-next-line import { sayHelloFunctionHandler } from './functions/say-hello/resource'; @@ -204,10 +205,9 @@ defineBackend({ Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your Function. -To invoke your Function, we recommend adding your [Function as a handler for a custom query with your Amplify Data resource](/[platform]/build-a-backend/data/custom-business-logic/). This will enable you to strongly type Function arguments and the return statement, and use this to author your Function's business logic. To get started, open your `amplify/data/resource.ts` file and specify a new query in your schema: +To invoke your function, we recommend adding your [function as a handler for a custom query with your Amplify Data resource](/[platform]/build-a-backend/data/custom-business-logic/). To get started, open your `amplify/data/resource.ts` file and specify a new query in your schema: ```ts title="amplify/data/resource.ts" -Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your function. import { sayHelloFunctionHandler } from "../functions/say-hello/resource" const schema = a.schema({ From 4989b85e336b2784d3cdb8a1cc86c57b87e2d035 Mon Sep 17 00:00:00 2001 From: Burak Karahan Date: Wed, 8 Jan 2025 18:57:29 +0300 Subject: [PATCH 5/7] chore: fix capitalization in documentation. --- .../build-a-backend/functions/custom-functions/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx index 41a6ec0516e..5a67769ed07 100644 --- a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -203,7 +203,7 @@ defineBackend({ }); ``` -Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your Function. +Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your function. To invoke your function, we recommend adding your [function as a handler for a custom query with your Amplify Data resource](/[platform]/build-a-backend/data/custom-business-logic/). To get started, open your `amplify/data/resource.ts` file and specify a new query in your schema: From 1ca323f5f550f8022e0cd0e6126782eb4ab1b09e Mon Sep 17 00:00:00 2001 From: Burak Karahan Date: Wed, 8 Jan 2025 19:26:40 +0300 Subject: [PATCH 6/7] Update src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx Co-authored-by: josef --- .../build-a-backend/functions/custom-functions/index.mdx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx index 5a67769ed07..3ffac8fb685 100644 --- a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -38,9 +38,6 @@ AWS Amplify Gen 2 functions are AWS Lambda functions that can be used to perform -Technically, you can use any language supported by AWS Lambda. These are NodeJS, Python, Java, .NET, Ruby. -To use other languages in Lambda, such as Go or Rust, use an OS-only runtime. - In this guide, you will learn how to create Python and Go functions with Amplify functions. The examples shown in this guide do not use Docker to build functions. Instead, the examples use commands that run on your host system to build, and as such require the necessary tooling for the language you are using for your functions. ## Python From 724c4f4cd0abdc270d586dd76062b1a348f05f5f Mon Sep 17 00:00:00 2001 From: josef Date: Wed, 8 Jan 2025 08:44:58 -0800 Subject: [PATCH 7/7] Update src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx --- .../build-a-backend/functions/custom-functions/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx index 3ffac8fb685..20974c6780b 100644 --- a/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx @@ -120,7 +120,7 @@ export const sayHelloFunctionHandler = defineFunction( (scope) => new Function(scope, "say-hello", { handler: "bootstrap", - runtime: Runtime.PROVIDED_AL2023, // or any other python version + runtime: Runtime.PROVIDED_AL2023, timeout: Duration.seconds(3), // default is 3 seconds code: Code.fromAsset(functionDir, { bundling: {