You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/functions/custom-functions/index.mdx
+24-29
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
3
3
exportconst meta = {
4
4
title: 'Custom functions',
5
5
description:
6
-
'Use another AWS Lambda runtimes like python, golang to perform tasks and customize workflows.',
6
+
'Use another AWS Lambda runtimes like Python, Golang to perform tasks and customize workflows.',
7
7
platforms: [
8
8
'android',
9
9
'angular',
@@ -30,29 +30,29 @@ export function getStaticProps(context) {
30
30
};
31
31
}
32
32
33
-
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:
33
+
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).
34
34
35
35
<Calloutwarning>
36
36
37
-
**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.
37
+
**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.
38
38
39
39
</Callout>
40
40
41
41
Technically, you can use any language supported by AWS Lambda. These are NodeJS, Python, Java, .NET, Ruby.
42
42
To use other languages in Lambda, such as Go or Rust, use an OS-only runtime.
43
43
44
-
In this guide, you will learn how to create python and golang functions in Amplify Functions.
44
+
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.
45
45
46
-
# Python functions
47
-
To get started, create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the Function with `defineFunction`:
46
+
## Python
48
47
48
+
To get started, create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the function with `defineFunction`:
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).
97
+
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).
98
98
99
-
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.
99
+
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.
100
100
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:
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.
108
108
109
-
# Go functions
110
-
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:
111
-
```npmi @aws-cdk/aws-lambda-go-alpha```
112
-
113
-
create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the Function with `defineFunction`:
109
+
## Go
110
+
To get started, Create a new directory and a resource file, `amplify/functions/say-hello/resource.ts`. Then, define the function with `defineFunction`:
@@ -212,7 +207,7 @@ Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will inclu
212
207
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:
213
208
214
209
```ts title="amplify/data/resource.ts"
215
-
import { typeClientSchema, a, defineData } from"@aws-amplify/backend"
210
+
Now when you run `npx ampx sandbox` or deploy your app on Amplify, it will include your function.
216
211
import { sayHelloFunctionHandler } from "../functions/say-hello/resource"
0 commit comments