Skip to content

(aws-iam): Invalid Policy Statement Id strings should fail at build time #34819

Open
@camerondurham

Description

@camerondurham

Describe the bug

Setting sid in PolicyStatement to a non-alphanumeric string results in a successful build but unsuccessful deployment.

Regression Issue

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

Last Known Working CDK Library Version

No response

Expected Behavior

Setting sid in PolicyStatement to a non-alphanumeric string fails CDK build with a helpful error message.

Current Behavior

Set policy statement to an invalid statement id string results in successful build.

const statement = new PolicyStatement({ sid: 'some-string' });

But when trying to deploy the statement, results in deployment failure:

Resource handler returned message: "Statement IDs (SID) must be alpha-numeric. Check that your input satisfies the regular expression [0-9A-Za-z]* (Service: Iam, Status Code: 400, 

Reproduction Steps

const statement = new PolicyStatement({ sid: 'string-with-non-alphanumeric-symbols' });

But when trying to deploy the statement, results in deployment failure:

Resource handler returned message: "Statement IDs (SID) must be alpha-numeric. Check that your input satisfies the regular expression [0-9A-Za-z]* (Service: Iam, Status Code: 400, 

Possible Solution

Test sid with the specific regex ([0-9A-Za-z]*) required in IAM docs: The Sid element supports ASCII uppercase letters (A-Z), lowercase letters (a-z), and numbers (0-9).

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

aws-cdk-lib@2.140.0

AWS CDK CLI version

2.140.0

Node.js Version

v18.20.4

OS

macOS

Language

TypeScript

Language Version

~4.6.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-iamRelated to AWS Identity and Access ManagementbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions