-
Notifications
You must be signed in to change notification settings - Fork 4k
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_logs: CfnAccountPolicy Returns bad request #31266
Comments
Hi @LucasSymons , thanks for reporting this. with open('/policy_doc.json', 'r') as file:
data = json.load(file)
cfn_account_policy = logs.CfnAccountPolicy(self, "MyCfnAccountPolicy",
policy_document=json.dumps(data),
policy_name="policyName",
policy_type="DATA_PROTECTION_POLICY",
scope="ALL",
) Although the Since CfnAccountPolicy is L1 construct , this is a Cloudformation issue. |
Internal ticket filed with Cloudformation support - P151743364 |
I experienced the same exact issue yesterday when trying to create the following resource: new CfnAccountPolicy(this, "LogsAccountPolicy", {
policyName: "LambdaSubscriptionPolicy",
policyDocument: JSON.stringify({
destinationArn: logProcessorFunction.functionArn,
filterPattern: "{ $.__otel_otlp_stdout = * }",
distribution: "Random",
}),
policyType: "SUBSCRIPTION_FILTER_POLICY",
scope: "ALL",
selectionCriteria: `LogGroupName NOT IN ["/aws/${logProcessorFunction.functionName}"]`,
}); The equivalent SAM template was working just fine: LogsAccountPolicy:
Type: AWS::Logs::AccountPolicy
Properties:
PolicyName: "LambdaSubscriptionPolicy"
PolicyDocument:
Fn::Sub: |
{
"DestinationArn": "${LogProcessorFunction.Arn}",
"FilterPattern": "{ $.__otel_otlp_stdout = * }",
"Distribution": "Random"
}
PolicyType: "SUBSCRIPTION_FILTER_POLICY"
Scope: "ALL"
SelectionCriteria: !Sub "LogGroupName NOT IN [\"/aws/${LogProcessorFunction}\"]" |
The error message is extremely vague here. In my case, I found that it was actually a permissions issue, not an issue with the this.addPermission("LogProcessorPermission", {
principal: new ServicePrincipal("logs.amazonaws.com"),
action: "lambda:InvokeFunction",
sourceArn: `arn:aws:logs:${props.env.region}:${props.env.account}:log-group:*`,
sourceAccount: props.env.account,
}); Be very careful with And if anyone stumbles upon this issue for another reason, here's our full new CfnAccountPolicy(this, "LogProcessorSubscriptionPolicy", {
policyDocument: JSON.stringify({
DestinationArn: this.functionArn,
FilterPattern: `{ ($.level = "warn") || ($.level = "error") || ($.level = "fatal") || ($.errorMessage = *) }`,
Distribution: "Random",
}),
policyName: "LogProcessorSubscriptionPolicy",
policyType: "SUBSCRIPTION_FILTER_POLICY",
scope: "ALL",
selectionCriteria: `LogGroupName NOT IN ["${this.LogGroup.logGroupName}"]`,
}); |
Describe the bug
When creating an AccountPolicy via cdk, I get back a request error.
"Invalid request provided: AWS::Logs::AccountPolicy" (RequestToken: 717f24d1-38cd-2b20-b7a1-1b04be946d9f, HandlerErrorCode: InvalidRequest)
Testing the stack with
cdk synth
no errors are returned.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
Expected successful creation or an obvious error about what the problem is.
Current Behavior
Reproduction Steps
The Policy file in use is below
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.154.1 (build febce9d)
Framework Version
No response
Node.js Version
v20.10.0
OS
MacOS 14.6.1
Language
Python
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: