-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(function): add custom functions documentation for AWS Amplify-backend #8176
base: main
Are you sure you want to change the base?
feature(function): add custom functions documentation for AWS Amplify-backend #8176
Conversation
… Gen 2 @aws-amplify/amplify-backend/1602
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left two comments around docker and go. But I suggest to wait until @josefaidt gets a chance to review this before making changes.
<Callout warning> | ||
|
||
**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. | ||
|
||
</Callout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Callout warning> | |
**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. | |
</Callout> | |
<Callout warning> | |
**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. | |
</Callout> |
|
||
# 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``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should refrain from using alpha packages in docs.
We should:
- either convert this sample to use
Code.from..
and plainFunction
(like in case of python). - or just remove Go sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an example of how this can be implemented using Function
:
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));
export const sendSmsGoFunctionHandler = defineFunction(
(scope) =>
new Function(scope, "SendSmsGo", {
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/handler.ts`. This is where your function code will go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be amplify/functions/say-hello/index.py
instead of amplify/functions/say-hello/handler.ts
?
… Gen 2 @aws-amplify/amplify-backend/1602
Description of changes:
Add custom runtime documents, it's required for #1602
Related GitHub issue
#1543, #1486
Instructions
Which product(s) are affected by this PR (if applicable)?
Which platform(s) are affected by this PR (if applicable)?
Please add the product(s)/platform(s) affected to the PR title
amplify-backend
Checks
When this PR is ready to merge, please check the box below
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.