private void setLocalSageMakerResourcesConfig()

in src/main/java/com/awslabs/aws/greengrass/provisioner/implementations/helpers/BasicFunctionHelper.java [508:551]


    private void setLocalSageMakerResourcesConfig(ImmutableFunctionConf.Builder functionConfBuilder, Config config) {
        List<? extends ConfigObject> configObjectList = config.getObjectList("conf.localSageMakerResources");

        if (configObjectList.size() == 0) {
            log.debug(String.join("", "No local SageMaker resources specified for [", functionConfBuilder.build().getFunctionName().getName(), "] function"));
            return;
        }

        for (ConfigObject configObject : configObjectList) {
            Config temp = configObject.toConfig();
            String arn = temp.getString(ARN);
            String path = temp.getString(PATH);

            String[] arnComponents = arn.split(":");

            // Validate the ARN. Regex for the ARN is: arn:aws[a-z\-]*:sagemaker:[a-z0-9\-]*:[0-9]{12}:training-job/.*
            // Regex from https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTrainingJob.html

            if (arnComponents.length != 6) {
                throw new RuntimeException(String.join("", "SageMaker ARN looks malformed [", arn, "]"));
            }

            if (!arnComponents[2].equals("sagemaker")) {
                throw new RuntimeException(String.join("", "SageMaker ARN does not look like a SageMaker ARN [", arn, "]"));
            }

            arnComponents = arnComponents[5].split("/");

            if (arnComponents.length < 2) {
                throw new RuntimeException(String.join("", "SageMaker ARN looks malformed [", arn, "]"));
            }

            if (!arnComponents[0].equals(TRAINING_JOB)) {
                throw new RuntimeException(String.join("", "SageMaker ARNs must be training job ARNs, not model ARNs or other types of ARNs [", arn, "]"));
            }

            LocalSageMakerResource localSageMakerResource = ImmutableLocalSageMakerResource.builder()
                    .arn(arn)
                    .path(path)
                    .build();

            functionConfBuilder.addLocalSageMakerResources(localSageMakerResource);
        }
    }