aws-cloudformation / community-registry-extensions

MIT No Attribution
85 stars 27 forks source link

AwsCommunity::ApplicationAutoscaling::ScheduledAction returns Internal Failure with ScalableTargetAction #255

Closed Daniel-ZA closed 6 months ago

Daniel-ZA commented 7 months ago

Extension Name

AwsCommunity::ApplicationAutoscaling::ScheduledAction

Describe the bug

Issue Description

Hi team,

I'm facing the error below using the third-party registry extension AwsCommunity::ApplicationAutoscaling::ScheduledAction when MaxCapacity and MinCapacity are both set to zero 0 in the ScalableTargetAction property.

Create error - ValidationException('An error occurred (ValidationException) when calling the PutScheduledAction operation: At least one of minimum capacity and maximum capacity should be provided')" (RequestToken: a1098eef-cadf-8842-8c06-2812bbee4bc9, HandlerErrorCode: InternalFailure)

Input:

{
    "Timezone": "Europe/London",
    "ScheduledActionName": "Scale.Down.Zero",
    "ResourceId": "service/ECSSample/nginx",
    "Schedule": "cron(10 8 ? * MON-FRI)",
    "ServiceNamespace": "ecs",
    "ScalableDimension": "ecs:service:DesiredCount",
    "ScalableTargetAction": {
      "MinCapacity": "0",
      "MaxCapacity": "0"
    }
}

Template:

Resources:
  ScaleDownZero:
    Properties:
      ResourceId: "service/ECSSample/nginx"
      ScalableDimension: "ecs:service:DesiredCount"
      ScalableTargetAction:
        MaxCapacity: 0
        MinCapacity: 0
      Schedule: cron(10 8 ? * MON-FRI)
      ScheduledActionName: Scale.Down.Zero
      ServiceNamespace: "ecs"
      Timezone: Europe/London
    Type: AwsCommunity::ApplicationAutoscaling::ScheduledAction

The API responsible for throwing the error above is PutScheduledAction:

{
    "eventVersion": "1.08",
    "userIdentity": {
            ...
    },
    "eventTime": "2023-11-21T10:19:30Z",
    "eventSource": "autoscaling.amazonaws.com",
    "eventName": "PutScheduledAction",
    "awsRegion": "eu-west-1",
    "errorCode": "ValidationException",
    "errorMessage": "At least one of minimum capacity and maximum capacity should be provided",
    "requestParameters": {
        "resourceId": "service/ECSSample/nginx",
        "scalableTargetAction": {},
        "scheduledActionName": "Scale.Down.Zero",
        "scalableDimension": "ecs:service:DesiredCount",
        "serviceNamespace": "ecs",
        "timezone": "Europe/London",
        "schedule": "cron(10 8 ? * MON-FRI)"
    },
    "responseElements": null,
    "additionalEventData": {
        "service": "application-autoscaling"
    },
}

I noticed that the scalableTargetAction property in the requestParameters is empty when the call is made from CFN but when the same call with same configuration properties is called by AWS CLI the scalableTargetAction is correctly populated with the maxCapacity and minCapacity which results in a successful creation:

CLI:

aws application-autoscaling put-scheduled-action --service-namespace ecs --scalable-dimension ecs:service:DesiredCount --resource-id service/ECSSample/nginx --scheduled-action-name scale-down-zero --schedule "cron(25 9 ? * MON-FRI)" --scalable-target-action MinCapacity=0,MaxCapacity=0

API CALL:

    "requestParameters": {
        "resourceId": "service/ECSSample/nginx",
        "scalableTargetAction": {
            "maxCapacity": 0,
            "minCapacity": 0
        },
        "scheduledActionName": "Scale.Down.Zero",
        "scalableDimension": "ecs:service:DesiredCount",
        "serviceNamespace": "ecs",
        "timezone": "Europe/London",
        "schedule": "cron(10 8 ? * MON-FRI)"
    },
    "responseElements": null,
    "additionalEventData": {
        "service": "application-autoscaling"
    },

In summary, the issue lies when MinCapacity and MaxCapacity are both set to zero under ScalableTargetAction property using CloudFormation and when it passes it to the PutScheduledAction API, the scalableTargetAction property is empty which results in the error even though they (maxCapacity, minCapacity) were supplied in the template. I'm not sure if this is an issue with the third-party registry or with CloudFormation. The schema for AwsCommunity::ApplicationAutoscaling::ScheduledAction is outlined here.

Thanks team let me know if need further info.

Expected behavior

ScalableTargetAction is populated with the maxCapacity and minCapacity.

Reproduction template

Resources:
  ScaleDownZero:
    Properties:
      ResourceId: "service/ECSSample/nginx"
      ScalableDimension: "ecs:service:DesiredCount"
      ScalableTargetAction:
        MaxCapacity: 0
        MinCapacity: 0
      Schedule: cron(10 8 ? * MON-FRI)
      ScheduledActionName: Scale.Down.Zero
      ServiceNamespace: "ecs"
      Timezone: "Europe/London"
    Type: AwsCommunity::ApplicationAutoscaling::ScheduledAction