Skip to content

Resource timed out waiting for creation of physical resource #210

@samgurtman-zz

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
                ));
    }

}

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