Skip to content

Resource timed out waiting for creation of physical resource #210

Closed

Description

@samgurtman-zz

Hello,

Thanks for releasing it. Hopefully it will prove useful to a lot of people. I'm trialling it by transferring an existing custom resource to this new system. I'm trying to utilize the chaining functionality but I've hit a bit of a wall. When I utilize the new resource Cloudformation fails with Resource timed out waiting for creation of physical resource. Interestingly, after this occurs I can see that the handler does run the stabilization part of the chain and complete (but Cloudformation has already failed by this part). I've copied the create handler below. Any obvious issues you can see?

public class CreateHandler extends BaseHandler<CallbackContext> {

    @Override
    public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
        final AmazonWebServicesClientProxy proxy,
        final ResourceHandlerRequest<ResourceModel> request,
        CallbackContext callbackContext,
        final Logger logger) {
        return proxy.initiate("ecs:CreateService", proxy.newProxy(EcsClient::create), request.getDesiredResourceState(), callbackContext == null ? new CallbackContext() : callbackContext)
                .request(model -> ResourceModelConverter.toCreateServiceRequest(model, request.getDesiredResourceTags()))
                .retry(Constant.of().delay(Duration.ofSeconds(20)).timeout(Duration.ofMinutes(60)).build())

                .call((createServiceRequest, client) ->
                        client.injectCredentialsAndInvokeV2(createServiceRequest, client.client()::createService))
                .stabilize((createServiceRequest, createServiceResponse, client, model, context) -> {
                    logger.log("Running stabilization test");
                    String expectedPrimaryId = createServiceResponse.service().deployments().stream().filter(
                            deployment -> deployment.status().equals("PRIMARY")
                    ).findAny()
                            .map(Deployment::id)
                            .orElseThrow(() -> new CfnGeneralServiceException("Should have one primary deployment in service"));

                    DescribeServicesRequest describeServicesRequest = DescribeServicesRequest.builder()
                            .services(createServiceResponse.service().serviceArn())
                            .cluster(createServiceResponse.service().clusterArn())
                            .build();

                    List<Service> services = client.injectCredentialsAndInvokeV2(describeServicesRequest, client.client()::describeServices).services();
                    if (services.size() != 1) {
                        throw new CfnGeneralServiceException("Could not find service which was created");
                    }

                    List<Deployment> updatedDeployments = services.get(0).deployments();
                    Deployment primaryLatest = updatedDeployments.stream()
                            .filter(deployment -> deployment.status().equals("PRIMARY"))
                            .filter(deployment -> deployment.id().equals(expectedPrimaryId))
                            .findAny()
                            .orElseThrow(() -> new CfnGeneralServiceException("Service has been modified from expected configuration"));
                    boolean notInProgress = updatedDeployments.stream()
                            .allMatch(deployment -> deployment.status().equals("PRIMARY") || deployment.status().equals("INACTIVE"));
                    if (!notInProgress) {
                        throw new CfnGeneralServiceException("Deployment has been modified concurrently");
                    }


                    boolean done = primaryLatest.runningCount().equals(primaryLatest.desiredCount());
                    if (!done) {
                        Integer maximumFailures = model.getAllowableStartupFailures();
                        if (maximumFailures == null) {
                            maximumFailures = 0;
                        }
                        if (BadCreateDetection.badExits(client, expectedPrimaryId, createServiceResponse.service().clusterArn()) > maximumFailures) {
                            throw new CfnGeneralServiceException("Some containers failed during startup");
                        }
                    }

                    return primaryLatest.runningCount().equals(primaryLatest.desiredCount());

                }).done((createServiceRequest, createServiceResponse, ecsClient, resourceModel, context) -> ProgressEvent.success(
                        ResourceModelConverter.merge(createServiceResponse.service(), resourceModel),
                        context
                ));
    }

}

Activity

  1. dchakrav-github commented on Nov 20, 2019

    @dchakrav-github
    Contributor

    thanks for raising the issue. Looking into it right now.

    1. Could you provide your model schema so that we can understand what your primary identifier is?
    2. In the stabilize call you would need to update the model with the primary identifier. That helps to signal to CloudFormation that we have completed the create call and are in stabilization mode.
    3. There is a small change needed on our end as well, that we will provide a fix soon
  2. samgurtman-zz commented on Nov 20, 2019

    @samgurtman-zz
    Author

    My primary identifier is the Arn of the ECS Service. I've fixed that particular problem by setting it during the stabilization process. Now I'm getting a different error in cloudwatch logs:

    Failed to schedule re-invoke, caused by software.amazon.awssdk.services.cloudwatchevents.model.CloudWatchEventsException: 1 validation error detected: Value '
    {
      ... large chunk of JSON with sensitive data.
    }
    ' at 'targets.1.member.input' failed to satisfy constraint: Member must have length less than or equal to 8192 (Service: CloudWatchEvents, Status Code: 400, Request ID: 7c3d8812-322d-4d96-886a-edd226125c03)
    

    My model for reference:

    {
        "typeName" : "EROAD::ECS::Service",
        "description" : "Resource Type definition for EROAD::ECS::Service",
        "additionalProperties" : false,
        "handlers": {
            "create": {
                "permissions": [
                    "ecs:CreateService",
                    "ecs:DescribeServices",
                    "ecs:ListTasks",
                    "ecs:DescribeTasks",
                    "iam:PassRole"
                ]
            },
            "read": {
                "permissions": [
                    "ecs:DescribeServices"
                ]
            },
            "update": {
                "permissions": [
                    "esc:DescribeServices",
                    "ecs:ListTasks",
                    "ecs:DescribeTasks",
                    "ecs:UpdateService",
                    "iam:PassRole"
                ]
            },
            "delete": {
                "permissions": [
                    "esc:DescribeServices",
                    "ecs:DeleteService"
                ]
            }
        },
        "properties" : {
            "ServiceArn" : {
                "type" : "string"
            },
            "Name" : {
                "type" : "string"
            },
            "Cluster" : {
                "type" : "string"
            },
            "DeploymentConfiguration" : {
                "$ref" : "#/definitions/DeploymentConfiguration"
            },
            "DesiredCount" : {
                "type" : "integer"
            },
            "InitialDesiredCount" : {
                "type" : "integer"
            },
            "AllowableStartupFailures" : {
                "type" : "integer"
            },
            "EnableECSManagedTags" : {
                "type" : "boolean"
            },
            "HealthCheckGracePeriodSeconds" : {
                "type" : "integer"
            },
            "LaunchType" : {
                "type" : "string"
            },
            "LoadBalancers" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/LoadBalancer"
                }
            },
            "NetworkConfiguration" : {
                "$ref" : "#/definitions/NetworkConfiguration"
            },
            "PlacementConstraints" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/PlacementConstraint"
                }
            },
            "PlacementStrategies" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/PlacementStrategy"
                }
            },
            "PlatformVersion" : {
                "type" : "string"
            },
            "PropagateTags" : {
                "type" : "string"
            },
            "Role" : {
                "type" : "string"
            },
            "SchedulingStrategy" : {
                "type" : "string"
            },
            "ServiceName" : {
                "type" : "string"
            },
            "ServiceRegistries" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/ServiceRegistry"
                }
            },
            "Tags" : {
                "type" : "array",
                "uniqueItems" : false,
                "items" : {
                    "$ref" : "#/definitions/Tag"
                }
            },
            "TaskDefinition" : {
                "type" : "string"
            }
        },
        "definitions" : {
            "PlacementConstraint" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "Expression" : {
                        "type" : "string"
                    },
                    "Type" : {
                        "type" : "string"
                    }
                },
                "required" : [ "Type" ]
            },
            "ServiceRegistry" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "ContainerName" : {
                        "type" : "string"
                    },
                    "ContainerPort" : {
                        "type" : "integer"
                    },
                    "Port" : {
                        "type" : "integer"
                    },
                    "RegistryArn" : {
                        "type" : "string"
                    }
                }
            },
            "NetworkConfiguration" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "AwsvpcConfiguration" : {
                        "$ref" : "#/definitions/AwsVpcConfiguration"
                    }
                }
            },
            "LoadBalancer" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "ContainerName" : {
                        "type" : "string"
                    },
                    "ContainerPort" : {
                        "type" : "integer"
                    },
                    "LoadBalancerName" : {
                        "type" : "string"
                    },
                    "TargetGroupArn" : {
                        "type" : "string"
                    }
                },
                "required" : [ "ContainerPort" ]
            },
            "DeploymentConfiguration" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "MaximumPercent" : {
                        "type" : "integer"
                    },
                    "MinimumHealthyPercent" : {
                        "type" : "integer"
                    }
                }
            },
            "Tag" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "Key" : {
                        "type" : "string"
                    },
                    "Value" : {
                        "type" : "string"
                    }
                },
                "required" : [ "Value", "Key" ]
            },
            "PlacementStrategy" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "Field" : {
                        "type" : "string"
                    },
                    "Type" : {
                        "type" : "string"
                    }
                },
                "required" : [ "Type" ]
            },
            "AwsVpcConfiguration" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "AssignPublicIp" : {
                        "type" : "string"
                    },
                    "SecurityGroups" : {
                        "type" : "array",
                        "uniqueItems" : true,
                        "items" : {
                            "type" : "string"
                        }
                    },
                    "Subnets" : {
                        "type" : "array",
                        "uniqueItems" : true,
                        "items" : {
                            "type" : "string"
                        }
                    }
                },
                "required" : [ "Subnets" ]
            }
        },
        "required" : [ "TaskDefinition" ],
        "readOnlyProperties" : [ "/properties/Name", "/properties/ServiceArn" ],
        "createOnlyProperties" : [ "/properties/LaunchType", "/properties/PlatformVersion", "/properties/ServiceRegistries", "/properties/EnableECSManagedTags", "/properties/PlacementStrategies", "/properties/SchedulingStrategy", "/properties/Cluster", "/properties/Role", "/properties/PropagateTags", "/properties/LoadBalancers", "/properties/PlacementConstraints", "/properties/ServiceName", "/properties/InitialDesiredCount" ],
        "primaryIdentifier" : [ "/properties/ServiceArn" ]
    }
    

    Basically what I'm doing with this resource is automating rollback of an ECS service as the built in ECS resource is quite limited in this regard.

  3. rjlohan commented on Nov 20, 2019

    @rjlohan
    Contributor

    Seems like you've hit an issue with our logic for scheduling re-invocation through CloudWatchEvents: https://github.com/aws-cloudformation/aws-cloudformation-rpdk-java-plugin/blob/1dd595a016f2071180203ab299aa415c6f17b04d/src/main/java/software/amazon/cloudformation/scheduler/CloudWatchScheduler.java#L115

    We're hitting this limit: https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_Target.html#eventbridge-Type-Target-Input

    We'll have to make some changes to fix this issue. Thanks for picking this up!

  4. dchakrav-github commented on Nov 22, 2019

    @dchakrav-github
    Contributor

    Can you attach a redacted template with just the resource usage and CreateHandler code here? That would be very helpful.

  5. samgurtman-zz commented on Nov 22, 2019

    @samgurtman-zz
    Author
  6. samgurtman-zz commented on Nov 27, 2019

    @samgurtman-zz
    Author

    Will leave open for re-invocation bug. Otherwise the original issue is resolved.

  7. dchakrav-github commented on Dec 2, 2019

    @dchakrav-github
    Contributor

    Whenever you do get time, please do have samples attached to the issue. I have used your existing definition for the time being,

  8. samgurtman-zz commented on Dec 9, 2019

    @samgurtman-zz
    Author

    fargate-service.tar.gz

    This is a version that still has the issue with the cloudwatch events bug. My production version has a workaround for it (involving trimming down the initial AWS response).

  9. ammokhov commented on Sep 23, 2020

    @ammokhov
    Contributor

    My primary identifier is the Arn of the ECS Service. I've fixed that particular problem by setting it during the stabilization process. Now I'm getting a different error in cloudwatch logs:

    Failed to schedule re-invoke, caused by software.amazon.awssdk.services.cloudwatchevents.model.CloudWatchEventsException: 1 validation error detected: Value '
    {
      ... large chunk of JSON with sensitive data.
    }
    ' at 'targets.1.member.input' failed to satisfy constraint: Member must have length less than or equal to 8192 (Service: CloudWatchEvents, Status Code: 400, Request ID: 7c3d8812-322d-4d96-886a-edd226125c03)
    

    My model for reference:

    {
        "typeName" : "EROAD::ECS::Service",
        "description" : "Resource Type definition for EROAD::ECS::Service",
        "additionalProperties" : false,
        "handlers": {
            "create": {
                "permissions": [
                    "ecs:CreateService",
                    "ecs:DescribeServices",
                    "ecs:ListTasks",
                    "ecs:DescribeTasks",
                    "iam:PassRole"
                ]
            },
            "read": {
                "permissions": [
                    "ecs:DescribeServices"
                ]
            },
            "update": {
                "permissions": [
                    "esc:DescribeServices",
                    "ecs:ListTasks",
                    "ecs:DescribeTasks",
                    "ecs:UpdateService",
                    "iam:PassRole"
                ]
            },
            "delete": {
                "permissions": [
                    "esc:DescribeServices",
                    "ecs:DeleteService"
                ]
            }
        },
        "properties" : {
            "ServiceArn" : {
                "type" : "string"
            },
            "Name" : {
                "type" : "string"
            },
            "Cluster" : {
                "type" : "string"
            },
            "DeploymentConfiguration" : {
                "$ref" : "#/definitions/DeploymentConfiguration"
            },
            "DesiredCount" : {
                "type" : "integer"
            },
            "InitialDesiredCount" : {
                "type" : "integer"
            },
            "AllowableStartupFailures" : {
                "type" : "integer"
            },
            "EnableECSManagedTags" : {
                "type" : "boolean"
            },
            "HealthCheckGracePeriodSeconds" : {
                "type" : "integer"
            },
            "LaunchType" : {
                "type" : "string"
            },
            "LoadBalancers" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/LoadBalancer"
                }
            },
            "NetworkConfiguration" : {
                "$ref" : "#/definitions/NetworkConfiguration"
            },
            "PlacementConstraints" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/PlacementConstraint"
                }
            },
            "PlacementStrategies" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/PlacementStrategy"
                }
            },
            "PlatformVersion" : {
                "type" : "string"
            },
            "PropagateTags" : {
                "type" : "string"
            },
            "Role" : {
                "type" : "string"
            },
            "SchedulingStrategy" : {
                "type" : "string"
            },
            "ServiceName" : {
                "type" : "string"
            },
            "ServiceRegistries" : {
                "type" : "array",
                "uniqueItems" : true,
                "items" : {
                    "$ref" : "#/definitions/ServiceRegistry"
                }
            },
            "Tags" : {
                "type" : "array",
                "uniqueItems" : false,
                "items" : {
                    "$ref" : "#/definitions/Tag"
                }
            },
            "TaskDefinition" : {
                "type" : "string"
            }
        },
        "definitions" : {
            "PlacementConstraint" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "Expression" : {
                        "type" : "string"
                    },
                    "Type" : {
                        "type" : "string"
                    }
                },
                "required" : [ "Type" ]
            },
            "ServiceRegistry" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "ContainerName" : {
                        "type" : "string"
                    },
                    "ContainerPort" : {
                        "type" : "integer"
                    },
                    "Port" : {
                        "type" : "integer"
                    },
                    "RegistryArn" : {
                        "type" : "string"
                    }
                }
            },
            "NetworkConfiguration" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "AwsvpcConfiguration" : {
                        "$ref" : "#/definitions/AwsVpcConfiguration"
                    }
                }
            },
            "LoadBalancer" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "ContainerName" : {
                        "type" : "string"
                    },
                    "ContainerPort" : {
                        "type" : "integer"
                    },
                    "LoadBalancerName" : {
                        "type" : "string"
                    },
                    "TargetGroupArn" : {
                        "type" : "string"
                    }
                },
                "required" : [ "ContainerPort" ]
            },
            "DeploymentConfiguration" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "MaximumPercent" : {
                        "type" : "integer"
                    },
                    "MinimumHealthyPercent" : {
                        "type" : "integer"
                    }
                }
            },
            "Tag" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "Key" : {
                        "type" : "string"
                    },
                    "Value" : {
                        "type" : "string"
                    }
                },
                "required" : [ "Value", "Key" ]
            },
            "PlacementStrategy" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "Field" : {
                        "type" : "string"
                    },
                    "Type" : {
                        "type" : "string"
                    }
                },
                "required" : [ "Type" ]
            },
            "AwsVpcConfiguration" : {
                "type" : "object",
                "additionalProperties" : false,
                "properties" : {
                    "AssignPublicIp" : {
                        "type" : "string"
                    },
                    "SecurityGroups" : {
                        "type" : "array",
                        "uniqueItems" : true,
                        "items" : {
                            "type" : "string"
                        }
                    },
                    "Subnets" : {
                        "type" : "array",
                        "uniqueItems" : true,
                        "items" : {
                            "type" : "string"
                        }
                    }
                },
                "required" : [ "Subnets" ]
            }
        },
        "required" : [ "TaskDefinition" ],
        "readOnlyProperties" : [ "/properties/Name", "/properties/ServiceArn" ],
        "createOnlyProperties" : [ "/properties/LaunchType", "/properties/PlatformVersion", "/properties/ServiceRegistries", "/properties/EnableECSManagedTags", "/properties/PlacementStrategies", "/properties/SchedulingStrategy", "/properties/Cluster", "/properties/Role", "/properties/PropagateTags", "/properties/LoadBalancers", "/properties/PlacementConstraints", "/properties/ServiceName", "/properties/InitialDesiredCount" ],
        "primaryIdentifier" : [ "/properties/ServiceArn" ]
    }
    

    Basically what I'm doing with this resource is automating rollback of an ECS service as the built in ECS resource is quite limited in this regard.

    this issue has been solved by this #255 and #279

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions