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

(aws-apigatewayv2): CfnStage logging level ERROR not working #25930

Closed
FarrOut opened this issue Jun 11, 2023 · 4 comments
Closed

(aws-apigatewayv2): CfnStage logging level ERROR not working #25930

FarrOut opened this issue Jun 11, 2023 · 4 comments
Labels
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@FarrOut
Copy link

FarrOut commented Jun 11, 2023

Describe the bug

Setting ApiGWv2.CfnStage.loggingLevel is not deploying correct value.

Expected Behavior

When setting logging level to ERROR, the resulting setting in the physical resource should be set to "Errors Only"

Current Behavior

Setting logging level to ERROR, results in the physical resource being set to "Full Request and Response Logs".

Reproduction Steps

LoggingLevel parameter VS physical resource
OFF: "OFF"
INFO: "Full Request and Response Logs"
ERROR: "Full Request and Response Logs" (WRONG!)

import * as cdk from 'aws-cdk-lib';
import {CfnOutput, CfnParameter} from 'aws-cdk-lib';
import {Construct} from 'constructs';

import {CfnApi, CfnStage} from "aws-cdk-lib/aws-apigatewayv2";

export class ApiGatewayV2Stack extends cdk.Stack {


    constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        const api = new CfnApi(this, `${id}-api`, {
            name: "MockApi",
            protocolType: "WEBSOCKET",
            routeSelectionExpression: "$request.body.action",
        });

        new CfnOutput(this, 'ApiId',
            {
                description: "The API identifier.",
                value: api.attrApiId
            })
        new CfnOutput(this, 'ApiEndpoint',
            {
                description: "The default endpoint for an API.",
                value: api.attrApiEndpoint
            })
        new CfnOutput(this, 'ApiBasePath',
            {
                description: "Specifies how to interpret the base path of the API during import.",
                value: String(api.basePath)
            })
        new CfnOutput(this, 'ApiBodyS3Location',
            {
                description: "The S3 location of an OpenAPI definition.",
                value: String(api.bodyS3Location)
            })
        new CfnOutput(this, 'ApiDescription',
            {
                description: "The description of the API.",
                value: String(api.description)
            })
        new CfnOutput(this, 'ApiName',
            {
                description: "The name of the API.",
                value: String(api.name)
            })
        new CfnOutput(this, 'ApiProtocolType',
            {
                description: "The API protocol.",
                value: String(api.protocolType)
            })
        new CfnOutput(this, 'ApiVersion',
            {
                description: "A version identifier for the API.",
                value: String(api.version)
            })

        const loggingLevel = new CfnParameter(this, "LoggingLevel", {
            type: "String",
            description: "Specifies the logging level for this route.",
            default: 'INFO',
            allowedValues: ['INFO', 'ERROR', 'OFF'],
        });
        new CfnOutput(this, 'LoggingLevelParameter',
            {
                description: "A map that defines the stage variables for a Stage.",
                value: loggingLevel.valueAsString
            })

        const stage = new CfnStage(this, `${id}-stage`, {
            apiId: api.ref,
            stageName: `${id}-stage-${loggingLevel.valueAsString}`,
            autoDeploy: true,
            defaultRouteSettings: {
                dataTraceEnabled: true, // depends on logging role
                detailedMetricsEnabled: true,
                loggingLevel: loggingLevel.valueAsString,
            }
        });
        new CfnOutput(this, 'StageApiId',
            {
                description: "The API identifier.",
                value: String(stage.apiId)
            })
        new CfnOutput(this, 'StageName',
            {
                description: "Stage names can contain only alphanumeric characters, hyphens, and underscores, or be $default . Maximum length is 128 characters.",
                value: String(stage.stageName)
            })
        new CfnOutput(this, 'IsStageAutoDeploy',
            {
                description: "Specifies whether updates to an API automatically trigger a new deployment.",
                value: String(stage.autoDeploy)
            })
        new CfnOutput(this, 'StageClientCertId',
            {
                description: "The identifier of a client certificate for a Stage.",
                value: String(stage.clientCertificateId)
            })
        new CfnOutput(this, 'StageDeploymentIde',
            {
                description: "The deployment identifier for the API stage.",
                value: String(stage.deploymentId)
            })
        new CfnOutput(this, 'StageDescription',
            {
                description: "The description for the API stage.",
                value: String(stage.description)
            })
        new CfnOutput(this, 'StageVariables',
            {
                description: "A map that defines the stage variables for a Stage.",
                value: String(stage.stageVariables)
            })
        new CfnOutput(this, 'StageRouteSettings',
            {
                description: "Route settings for the stage.",
                value: String(stage.routeSettings)
            })

    }
}

Possible Solution

When setting logging level to "ERROR", set physical resource to "Errors Only" mode.

Additional Information/Context

No response

CDK CLI Version

2.83.1 (build 006b542)

Framework Version

No response

Node.js Version

v16.20.0

OS

Windows 10

Language

Typescript

Language Version

No response

Other information

No response

@FarrOut FarrOut added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 11, 2023
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Jun 11, 2023
@pahud
Copy link
Contributor

pahud commented Jun 12, 2023

Can you check the synthesized output and see if the value of loggingLevel is ERROR ? If yes but the value from the console is actuallyFull Request and Response Logs then I believe this might be a bug from cloudformation and we'll need to report this in cloudformation roadmap coverage.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 12, 2023
@FarrOut
Copy link
Author

FarrOut commented Jun 13, 2023

Oooh good point!

Just check again and confirmed, synthesized template sets value to ERROR, but the resource is still set to incorrect mode.

Opened ticket in Cloudformation Roadmap

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 13, 2023
@ashishdhingra
Copy link
Contributor

@FarrOut Please refer aws-cloudformation/cloudformation-coverage-roadmap#1712 (comment). Setting dataTraceEnabled: true will always set the CloudWatch Logs setting on the UI to Full Request and Response Logs. It's only if dataTraceEnabled is not set not true, then the logging level will be applied.

Closing this ticket. Feel free to reopen if it's still an issue.

Copy link

github-actions bot commented Jun 6, 2024

⚠️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-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants