Skip to content

add_cloudwatch_action <ec2 autorecover actions>: works only in aws partition #19765

@GregChapmanAtRack

Description

@GregChapmanAtRack

Describe the bug

When deploying EC2 instances in any partition other than commercial, stack rolls back when EC2 recover and reboot actions are added to an alarm.

Expected Behavior

Alarm to be created with specified action, for example:

cw_alarm4.add_alarm_action(cloudwatch_actions.Ec2Action(cloudwatch_actions.Ec2InstanceAction.REBOOT))

Current Behavior

"<timestamp>| CREATE_FAILED        | AWS::CloudWatch::Alarm    | CloudwatchAlarm287DB52F9
Invalid partition aws specified. Only aws-us-gov is supported. (Service: AmazonCloudWatch; Status Code: 400; Error Code: ValidationError; Request ID: f61066f0-d59c-42f0-bf39-99ea1c0d3cc2;
Proxy: null)"

Reproduction Steps

    cw_alarm4 = cloudwatch.Alarm(
        scope=self,
        id="Cloudwatch Alarm 4",
        comparison_operator=cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
        evaluation_periods=1,
        actions_enabled=True,
        alarm_description="Status checks have failed, REBOOTING/RECOVERING system - " +
        instance1,
        alarm_name="Instance Status Check Failed - "+instance1+" recovery",
        datapoints_to_alarm=None,
        metric=instance1_metric2,
        threshold=0,
        treat_missing_data=None
    )
    cw_alarm4.add_alarm_action(cloudwatch_actions.Ec2Action(
        cloudwatch_actions.Ec2InstanceAction.REBOOT))

Works in AWS partition. Does not work in aws-us-gov

Possible Solution

I believe the error resides in https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-cloudwatch-actions/lib/ec2.ts#L40-L46

Suggest distilling partition from env variable AWS_DEFAULT_REGION, .aws/config values, etc.

Additional Information/Context

No response

CDK CLI Version

2.19.0 (build e0d3e62)

Framework Version

No response

Node.js Version

v16.11.1

OS

NAME="Ubuntu" VERSION="20.04.4 LTS (Focal Fossa)"

Language

Python

Language Version

Python 3.10.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions