amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Log Groups Subscription & CloudwatchDashboard

Open leonardoas10 opened this issue 7 months ago • 2 comments

Describe the feature you'd like to request

Dear Amplify Team,

I’m encountering issues when trying to generate log subscriptions and a CloudWatch dashboard for functions in Amplify. Below are the key challenges and potential improvements:

  1. Automatic Log Group Creation in defineFunction()

Currently, there’s no built-in way to generate a default log group when defining a function. The log group is only created after the function runs for the first time, which causes issues when setting up log subscriptions.

export const test = defineFunction({
  name: 'test',
  entry: './handler.ts',
  memoryMB: 128,
  logger: true, // A boolean flag to create a default log group
});

Issue: Log subscriptions fail if the log group doesn’t exist yet (see point 2).

  1. Simplifying Log Subscriptions

Right now, log subscriptions must be created manually using CDK:

new logs.SubscriptionFilter(...);

This approach works but has some drawbacks: • (a) If the function’s log group hasn’t been created yet, subscription creation fails. • (b) There’s no straightforward way to retrieve all functions from backend.ts. Currently, we have to manually import each function, which is tedious.

A potential improvement could be a method like:

backend.getLambdas(); // Retrieves all functions (queries, mutations, etc.)

  1. Utility Method to Retrieve All Functions

Currently, to access generated functions inside backend.ts, we have to re-import them manually. A built-in method to get all functions dynamically would improve the developer experience.

  1. CloudWatch Dashboard Generation

The same problem arises when trying to generate CloudWatch dashboards dynamically. Without an easy way to retrieve all functions in backend.ts, automating dashboard widget creation in a loop is difficult.

Would it be possible to introduce a more streamlined way to access all functions for better observability support?

Thanks for considering these improvements!

Describe the solution you'd like

The solution as i said before is

  1. Log Group Generation: A boolean inside defineFunction could do the trick, for always generate this default log group without await until the first execution.
  2. Retrieve Lambdas: today doesn't exist away for get all lambdas in backend.ts
  3. Cloudwatch Dashboard: Maybe add this feature in the framework avoiding using CDK, as well as, log subscription filter?

Describe alternatives you've considered

Improve more the framework adding this new features for

  • Retrieve lambdas
  • Generate log group
  • Generate log subscriptions
  • Generate cloudwatch dashboard

Additional context

No response

Is this something that you'd be interested in working on?

  • [ ] 👋 I may be able to implement this feature request

Would this feature include a breaking change?

  • [ ] ⚠️ This feature might incur a breaking change

leonardoas10 avatar Mar 07 '25 15:03 leonardoas10