Skip to content

(custom_resources): incorrect IAM prefix generated for CloudWatch actions #32968

Closed
@konoui

Description

@konoui

Describe the bug

AwsCustomResource in custom_resources generates an incorrect IAM action prefix monitoring:<action> for CloudWatch actions. The correct prefix should be cloudwatch:<action>.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The generated IAM action prefix should be cloudwatch:<action>.

https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatch.html

Amazon CloudWatch (service prefix: cloudwatch) provides the following service-specific resources, actions, and condition context keys for use in IAM permission policies.

Current Behavior

The generated IAM action prefix is monitoring:<action>.

Reproduction Steps

  1. Use AwsCustomResource to create a resource for a CloudWatch action (e.g., tagResource).
  2. Run cdk synth.
  3. Observe the generated IAM policy in the synthesized template.
new custom_resources.AwsCustomResource(this, "CustomResource", {
  onCreate: {
    service: "CloudWatch",
    action: "tagResource",
    parameters: {
      ResourceARN: "dummy",
      Tags: [{ Key: "Name", Value: "prod" }],
    },
    physicalResourceId: custom_resources.PhysicalResourceId.of("add_tag"),
  },
  policy: custom_resources.AwsCustomResourcePolicy.fromSdkCalls({
    resources: custom_resources.AwsCustomResourcePolicy.ANY_RESOURCE,
  }),
});
cdk synth

(snip)
  CustomResourceCustomResourcePolicy887CD354:
    Type: AWS::IAM::Policy
    Properties:
      PolicyDocument:
        Statement:
          - Action: monitoring:TagResource
            Effect: Allow
            Resource: "*"
        Version: "2012-10-17"
      PolicyName: CustomResourceCustomResourcePolicy887CD354
      Roles:
        - Ref: AWS679f53fac002430cb0da5b7982bd2287ServiceRoleC1EA0FF2
(snip)

Possible Solution

The issue seems to originate in the sdk-v3-metadata.json file, which maps CloudWatch actions to the incorrect prefix monitoring.

https://github.com/aws/aws-cdk/blob/v2.176.0/packages/aws-cdk-lib/custom-resources/lib/helpers-internal/sdk-v3-metadata.json#L198

Additional Information/Context

No response

CDK CLI Version

2.176.0

Framework Version

No response

Node.js Version

v22.8.0

OS

macOS Monterey

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/custom-resourcesRelated to AWS CDK Custom ResourcesbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions