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

Sandbox function deployment does not compile TS into JS #1974

Closed
rpostulart opened this issue Sep 9, 2024 · 6 comments
Closed

Sandbox function deployment does not compile TS into JS #1974

rpostulart opened this issue Sep 9, 2024 · 6 comments
Labels
function Issue pertaining to Amplify Function pending-triage Incoming issues that need categorization

Comments

@rpostulart
Copy link

rpostulart commented Sep 9, 2024

Environment information

System:
  OS: macOS 14.6.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 37.20 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.2.0 - /usr/local/bin/node
  Yarn: undefined - undefined
  npm: 10.7.0 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.2.2
  @aws-amplify/backend: 1.1.1
  @aws-amplify/backend-auth: 1.1.2
  @aws-amplify/backend-cli: 1.2.3
  @aws-amplify/backend-data: 1.1.1
  @aws-amplify/backend-deployer: 1.0.5
  @aws-amplify/backend-function: 1.3.2
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.1
  @aws-amplify/backend-secret: 1.0.1
  @aws-amplify/backend-storage: 1.1.1
  @aws-amplify/cli-core: 1.1.2
  @aws-amplify/client-config: 1.2.0
  @aws-amplify/deployed-backend-client: 1.4.0
  @aws-amplify/form-generator: 1.0.1
  @aws-amplify/model-generator: 1.0.4
  @aws-amplify/platform-core: 1.0.6
  @aws-amplify/plugin-types: 1.2.1
  @aws-amplify/sandbox: 1.1.3
  @aws-amplify/schema-generator: 1.2.1
  aws-amplify: 6.5.1
  aws-cdk: Not Found
  aws-cdk-lib: 2.152.0
  typescript: 5.5.4
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

When I add a custom resource Lambda function and I would like to code this with Typescript. Then when saving the file a new trigger starts deploying, which is fine, but it does not compiles TS into JS in the lambda function. So I need to do this locally first and this triggers a new deployment again.

Can sandbox deployment automaticly compile ts into js during deployment

Reproduction steps

npx ampx sandbox

@rpostulart rpostulart added the pending-triage Incoming issues that need categorization label Sep 9, 2024
@ykethan
Copy link
Member

ykethan commented Sep 10, 2024

Hey @rpostulart, thank you for reaching out. Is the custom resource a Lambda function created using the CDK Lambda construct?
The Lambda NodeJS construct should provide this capability of automatic transpiling and bundling of TypeScript or Javascript code.
But curious on the use case for creating a custom lambda function as Amplify Gen 2 defineFunction already utilizes Lambda NodeJS construct to create the function.

@ykethan ykethan added pending-response Issue is pending response from author function Issue pertaining to Amplify Function labels Sep 10, 2024
@rpostulart
Copy link
Author

rpostulart commented Sep 10, 2024

Yes, this is the code which is created with CDK and imported as target for the eventbridge event which are also defined as CDK

import * as cdk from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";
import { Construct } from "constructs";

import * as iam from "aws-cdk-lib/aws-iam";

export class MailService extends Construct {
  public readonly lambdaFunction: lambda.Function;

  constructor(scope: Construct, id: string) {
    super(scope, id);

    // Define Lambda function
    this.lambdaFunction = new lambda.Function(this, "MailService", {
      runtime: lambda.Runtime.NODEJS_20_X,
      code: lambda.Code.fromAsset(
        "amplify/custom/services/mailService/src/src/"
      ),
      handler: "index.handler",
    });

    // Grant SES permissions (if needed)
    this.lambdaFunction.addToRolePolicy(
      new iam.PolicyStatement({
        effect: iam.Effect.ALLOW,
        actions: ["ses:SendEmail", "ses:SendRawEmail"],
        resources: ["*"], // You might want to restrict this to specific SES ARNs
      })
    );
  }
}

@github-actions github-actions bot removed the pending-response Issue is pending response from author label Sep 10, 2024
@ykethan
Copy link
Member

ykethan commented Sep 12, 2024

Hey @rpostulart, thank you for info is this a scheduled event or is this triggered by an AWS event? If this is a AWS event what service triggers this event?
The existing defineFunction does support scheduled functions, refer to scheduling functions documentation

@ykethan ykethan added the pending-response Issue is pending response from author label Sep 12, 2024
@rpostulart
Copy link
Author

This is indeed a scheduled event and targeted lambda by event bridge

@github-actions github-actions bot removed the pending-response Issue is pending response from author label Sep 19, 2024
@ykethan
Copy link
Member

ykethan commented Sep 20, 2024

@rpostulart thanks for the information, the NodejsFunction construct should help with your use case to transpile automatically.

@ykethan ykethan added the pending-response Issue is pending response from author label Sep 20, 2024
@rpostulart
Copy link
Author

ok that works, thanks!

@github-actions github-actions bot removed the pending-response Issue is pending response from author label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function Issue pertaining to Amplify Function pending-triage Incoming issues that need categorization
Projects
None yet
Development

No branches or pull requests

2 participants