Skip to content
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

Detailed docs for: Go, Python Runtimes functions, how can we create and assign these functions #1486

Open
MarlonJD opened this issue May 9, 2024 · 5 comments
Labels
feature-request New feature or request function Issue pertaining to Amplify Function p4

Comments

@MarlonJD
Copy link

MarlonJD commented May 9, 2024

Environment information

System:
  OS: macOS 14.4.1
  CPU: (8) arm64 Apple M2
  Memory: 361.41 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.20.2 - ~/.nvm/versions/node/v18.20.2/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 10.5.0 - ~/.nvm/versions/node/v18.20.2/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: 1.0.0
  @aws-amplify/backend-cli: 1.0.1
  aws-amplify: 6.3.0
  aws-cdk: 2.140.0
  aws-cdk-lib: 2.140.0
  typescript: 5.4.5
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

On AWS Amplify Gen 2 document, it says there is only nodejs runtimes for defineFunction Source

Currently, only Node runtimes are supported by defineFunction. However, you can change the Node version that is used by the function. The default is the oldest Node LTS version that is supported by AWS Lambda (currently Node 18).

On the Gen 1 vs. Gen 2 feature matrix. It says, Function runtime: .NET 6, Go, Java, Javascript and Python is available with Yes with CDK.

How can we create for example Go Lambda function and use as a custom GraphQL query in gen 2. There was detailed document on gen 1 for custom query with lambda function.

We were creating go function with amplify add function, then just assigning this function name with this:

type Query {
  echo(msg: String): String @function(name: "echofunction", region: "us-east-1")
}

Set up custom queries and mutations (Gen 1)

Now, how can we do this? Also we need to get current user's information with body, can we do this in gen 2 ? For example I'm using user's cognitoId to get user's detail and get permissions about custom job.

Which options we have? How can we connect our Golang function to custom query, can I get user's cognate id with this query?

@MarlonJD MarlonJD added the pending-triage Incoming issues that need categorization label May 9, 2024
@josefaidt
Copy link
Contributor

Hey @MarlonJD 👋 thanks for taking the time to file this, and thank you for stopping by office hours! It was great to have you there!

Marking as a feature request

@josefaidt josefaidt added feature-request New feature or request needs-product-input Needs non-technical requirements or direction to proceed function Issue pertaining to Amplify Function and removed pending-triage Incoming issues that need categorization labels May 9, 2024
@josefaidt josefaidt self-assigned this May 9, 2024
@MarlonJD
Copy link
Author

MarlonJD commented May 9, 2024

@josefaidt Hey there! Thank you for quick response. Office hours are great, likewise. I looking forward for this issue to migration.

@LukaASoban
Copy link

Just commenting on this thread as this is also something that I would highly appreciate :)

@MarlonJD
Copy link
Author

MarlonJD commented May 15, 2024

I just successfully created go runtime lamda function but I couldn't assign lambda resolver-function to appsync/graphql query or override to existing typescript function.

Here is the how I could created golang function:

import * as go from "@aws-cdk/aws-lambda-go-alpha";
import { Stack } from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";

export function createGoFunction(backend: any) {
  const lambdaStack = Stack.of(backend.sayHelloHandler.resources.lambda.stack);

  const functionName = "say-hello-go";

  const sayHelloGoHandler = new go.GoFunction(lambdaStack, "handler", {
    functionName: functionName,
    entry: "./amplify/functions/say-hello-go/",
    runtime: lambda.Runtime.PROVIDED_AL2023,
    environment: {
      GOARCH: "amd64",
    },
    bundling: {
      goBuildFlags: ["-tags lambda.norpc"],
    },
  });

  console.log("Go function arn:", functionName.replace(/[^0-9a-zA-Z]/g, ""));
  console.log(
    "Go function posible logicalID:",
    functionName.replace(/[^0-9a-zA-Z]/g, "")
  );
}

Edit: I think I found possible way, I don't sure but right place is DataSource I think, if I change AppSync's invoke function of related custom query name, there should be a datasource as lambda, if we create any typeScript function to create custom query, then change lambda function arn to golang lambda function's arn. It can be works, I'm trying to do this somehow in backend.ts with cdk.

Anyone can help how can I use this function in custom graphql query?

@josefaidt
Copy link
Contributor

josefaidt commented May 21, 2024

Hey @MarlonJD and @LukaASoban 👋 we've published an RFC #1543 for supporting other runtimes! Let us know what you think!

@josefaidt josefaidt removed the needs-product-input Needs non-technical requirements or direction to proceed label May 21, 2024
@josefaidt josefaidt removed their assignment May 21, 2024
@josefaidt josefaidt added the p4 label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request function Issue pertaining to Amplify Function p4
Projects
None yet
Development

No branches or pull requests

3 participants