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

Created log groups need a default policy. #157

Open
avirtual opened this issue Nov 21, 2023 · 1 comment
Open

Created log groups need a default policy. #157

avirtual opened this issue Nov 21, 2023 · 1 comment

Comments

@avirtual
Copy link

The created log groups do not have a default policy and that causes AWS to add more content to the regional resource policy, eventually reaching the limit of 5120 bytes.

10:40:31 AM | CREATE_FAILED        | AWS::ApiGatewayV2::Stage                        | apiApiDefaultStageA626ED4D
Cannot enable logging. Policy document length breaking Cloudwatch Logs Constraints, either < 1 or > 5120 (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: f34c406a-e69a-48de-b1a8-a68acd9cc0
70; Proxy: null)

In apibuilder.ts

const accessLogs = new logs.LogGroup(scope, "VAMS-API-AccessLogs");

In order to prevent that from happening (when deploying multiple stacks on the same region) something like this needs to be added

    const policyStatement = new iam.PolicyStatement({
        sid: "AWSLogDeliveryWrite20150319",
        effect: iam.Effect.ALLOW,
        principals: [new iam.ServicePrincipal("delivery.logs.amazonaws.com")],
        actions: ["logs:CreateLogStream", "logs:PutLogEvents"],
        resources: [`${accessLogs.logGroupArn}:log-stream:*`],
        conditions: {
            StringEquals: {
                "aws:SourceAccount": cdk.Stack.of(scope).account
            },
            ArnLike: {
                "aws:SourceArn": `arn:aws:logs:${cdk.Stack.of(scope).region}:${cdk.Stack.of(scope).account}:*`
            }
        }
    });

    accessLogs.addToResourcePolicy(policyStatement);

Same story in uploadAssetWorkflowBuilder.ts and potentially elsewhere.

@avirtual
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant