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

appsync: Log group for API is not created at deployment leading to "The specified log group does not exist" error when applying metric filter #26564

Closed
jzybert opened this issue Jul 28, 2023 · 7 comments · Fixed by #28548
Labels
@aws-cdk/aws-appsync Related to AWS AppSync bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@jzybert
Copy link

jzybert commented Jul 28, 2023

Describe the bug

I am deploying a GraphqlApi construct with a logConfig prop set with retention days as well. I am also calling api.logGroup.addMetricFilter in the same stack. However, I get this error Resource handler returned message: "The specified log group does not exist. It appears that the log group is not created even when the logConfig prop is provided upon deployment. This is causing newly deployed stacks to fail.

Expected Behavior

I would have expected the log group to be created when the API is created so that metric filters could be applied.

Current Behavior

I get a CloudFormation error of Resource handler returned message: "The specified log group does not exist and my stack fails to depoy.

Reproduction Steps

const api = new GraphqlApi(this, 'API', {
  name: 'api',
  schema: SchemaFile.fromAsset('schema.graphql'),
  logConfig: {
    fieldLogLevel: FieldLogLevel.ALL,
    retention: RetentionDays.ONE_WEEK,
    excludeVerboseContent: true
  },
});

api.logGroup.addMetricFilter('MetricFilter', {
  filterPattern: {
    logPatternString: '{ $.fieldName = "myQuery" && $.fieldInError IS TRUE }'
  },
  metricName: 'ErrorCount',
  metricNamespace: 'MyNamespace,
  metricValue: '1',
});

Possible Solution

It appears that the code is simply looking for a log group name but not actually generating its own log group when the API is created. See here. A fix for this would be to ensure the log group is actually created rather than trying to load it by name.

Additional Information/Context

Some additional context is that I'm using VTL templates for some of my API resolvers. Because they don't natively have their own log groups or metrics, I'm leveraging adding a metric filter to the main API log group which is where the template resolvers log their logs/errors to.

CDK CLI Version

2.88.0

Framework Version

No response

Node.js Version

18

OS

macOS Ventura 13.4

Language

Typescript

Language Version

5.0.4

Other information

No response

@jzybert jzybert added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 28, 2023
@github-actions github-actions bot added the @aws-cdk/aws-appsync Related to AWS AppSync label Jul 28, 2023
@pahud
Copy link
Contributor

pahud commented Jul 31, 2023

Looks like it assums the log group already exists.

const logGroupName = `/aws/appsync/apis/${this.apiId}`;
this.logGroup = LogGroup.fromLogGroupName(this, 'LogGroup', logGroupName);

Reading the doc I guess you will need to enable the logging first?
https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html

If this works for you, we probably should add this notice in the CDK doc.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 31, 2023
@jzybert
Copy link
Author

jzybert commented Jul 31, 2023

@pahud The logConfig is added if that's what you mean by enable logging first

@pahud
Copy link
Contributor

pahud commented Aug 1, 2023

@jzybert

No from what I see in the source code, adding the logConfig will not create log group for you from CDK. Instead, that log group seems to be managed by the AppSync service and will be created only when you turn on Enable Logs from the console as described in the doc. I am not sure what is the best way to deal with it but CDK appsync construct library at this moment seems to expect the log group exists so it can import that with fromLogGroupName() method.

@jzybert
Copy link
Author

jzybert commented Aug 1, 2023

@pahud ah, I see. Unfortunately that doesn't entirely work for us, because our CloudFormation stack deployment would fail after deploying the API but before enabling the logs then. Hoping for a CDK update here to support turning it on immediately after the API is created rather than needing to be a manual process

@idclipr
Copy link

idclipr commented Oct 16, 2023

We are hitting this bug too. Can GraphqlApi construct be updated to actually create the log group instead of assuming it exists? i.e. use new LogGroup() instead of fromLogGroupName()?

@yashmardikar
Copy link

yashmardikar commented Oct 17, 2023

For me even after logging was turned on, the log group was not getting created. I ran some queries and then log group was created. Is log group created lazily? This is not ideal.

For first time deployment in new account/region, deployment fails and then rollback takes at least 20 mins before i can try another deployment. Please Fix this.

mergify bot pushed a commit that referenced this issue Jan 18, 2024
…up (#28548)

This change adds a dependency to log retention if logconfig is set for `GraphqlApi`. This in turn avoids the race condition when subsequent resources refer to the log group property of `GraphqlApi.logGroup`

logGroup is now referring to the custom resource's output log ARN and further resources will depend on the custom resource to be created first.

Closes #26564

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot closed this as completed in #28548 Jan 18, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
4 participants