Skip to content

Commit

Permalink
docs(functions): clarify function invocation instructions and improve…
Browse files Browse the repository at this point in the history
… code examples in custom functions documentation
  • Loading branch information
MarlonJD committed Jan 7, 2025
1 parent 4b0242f commit eb92ef5
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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';

Expand All @@ -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({
Expand Down

0 comments on commit eb92ef5

Please sign in to comment.