private ProgressEvent createCanary()

in aws-synthetics-canary/src/main/java/com/amazon/synthetics/canary/CreateHandler.java [95:170]


    private ProgressEvent<ResourceModel, CallbackContext> createCanary() {
        final CanaryCodeInput canaryCodeInput = CanaryCodeInput.builder()
                .handler(model.getCode().getHandler())
                .s3Bucket(model.getCode().getS3Bucket())
                .s3Key(model.getCode().getS3Key())
                .s3Version(model.getCode().getS3ObjectVersion())
                .zipFile(model.getCode().getScript() != null ? ModelHelper.compressRawScript(model) : null)
                .build();

        Long durationInSeconds = !Strings.isNullOrEmpty(model.getSchedule().getDurationInSeconds()) ?
                Long.valueOf(model.getSchedule().getDurationInSeconds()) : null;

        final CanaryScheduleInput canaryScheduleInput = CanaryScheduleInput.builder()
                .expression(model.getSchedule().getExpression())
                .durationInSeconds(durationInSeconds)
                .build();

        int memoryInMb = DEFAULT_MEMORY_IN_MB;
        CanaryRunConfigInput canaryRunConfigInput = null;
        if (model.getRunConfig() != null) {
            // memoryInMb is optional input. Default value if no value is supplied
            memoryInMb = model.getRunConfig().getMemoryInMB() != null ?
                    model.getRunConfig().getMemoryInMB() : DEFAULT_MEMORY_IN_MB;

            canaryRunConfigInput = CanaryRunConfigInput.builder()
                .timeoutInSeconds(model.getRunConfig().getTimeoutInSeconds())
                .memoryInMB(memoryInMb)
                .activeTracing(Boolean.TRUE.equals(model.getRunConfig().getActiveTracing()))
                .environmentVariables(model.getRunConfig().getEnvironmentVariables())
                .build();
        }

        // VPC Config optional
        VpcConfigInput vpcConfigInput = null;

        if (model.getVPCConfig() != null) {
            vpcConfigInput = VpcConfigInput.builder()
                    .subnetIds(model.getVPCConfig().getSubnetIds())
                    .securityGroupIds(model.getVPCConfig().getSecurityGroupIds())
                    .build();
        }

        final CreateCanaryRequest createCanaryRequest = CreateCanaryRequest.builder()
                .name(model.getName())
                .executionRoleArn(model.getExecutionRoleArn())
                .schedule(canaryScheduleInput)
                .artifactS3Location(model.getArtifactS3Location())
                .runtimeVersion(model.getRuntimeVersion())
                .code(canaryCodeInput)
                .tags(ModelHelper.buildTagInputMap(model))
                .vpcConfig(vpcConfigInput)
                .failureRetentionPeriodInDays(model.getFailureRetentionPeriod())
                .successRetentionPeriodInDays(model.getSuccessRetentionPeriod())
                .runConfig(canaryRunConfigInput)
                .artifactConfig(ModelHelper.getArtifactConfigInput(model.getArtifactConfig()))
                .build();
        try {
            proxy.injectCredentialsAndInvokeV2(createCanaryRequest, syntheticsClient::createCanary);
        } catch (final ValidationException e) {
            if ( e.getMessage().contains("Canary name already exists") ) {
                throw new CfnAlreadyExistsException(ResourceModel.TYPE_NAME, e.getMessage(), e);
            } else {
                throw new CfnInvalidRequestException(e.getMessage());
            }
        } catch (final Exception e) {
            throw new CfnGeneralServiceException(e.getMessage());
        }

        context.setCanaryCreateStarted(true);
        return ProgressEvent.<ResourceModel, CallbackContext>builder()
                .callbackContext(context)
                .resourceModel(model)
                .status(OperationStatus.IN_PROGRESS)
                .callbackDelaySeconds(DEFAULT_CALLBACK_DELAY_SECONDS)
                .build();
    }