CustomModel class

Manages an Amazon Bedrock custom model. Model customization is the process of providing training data to a base model in order to improve its performance for specific use-cases.

This Terraform resource interacts with two Amazon Bedrock entities:

  1. A Continued Pre-training or Fine-tuning job which is started when the Terraform resource is created. The customization job can take several hours to run to completion. The duration of the job depends on the size of the training data (number of records, input tokens, and output tokens), and hyperparameters (number of epochs, and batch size).
  2. The custom model output on successful completion of the customization job.

This resource's behaviors correspond to operations on these Amazon Bedrock entities:

  • Create starts the customization job and immediately returns.
  • Read returns the status and results of the customization job. If the customization job has completed, the output model's properties are returned.
  • Update updates the customization job's tags.
  • Delete stops the customization job if it is still active. If the customization job has completed, the custom model output by the job is deleted.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = aws.bedrockfoundation.getModel({
    modelId: "amazon.titan-text-express-v1",
});
const exampleCustomModel = new aws.bedrock.CustomModel("example", {
    outputDataConfig: {
        s3Uri: `s3://${output.id}/data/`,
    },
    trainingDataConfig: {
        s3Uri: `s3://${training.id}/data/train.jsonl`,
    },
    customModelName: "example-model",
    jobName: "example-job-1",
    baseModelIdentifier: example.then(example => example.modelArn),
    roleArn: exampleAwsIamRole.arn,
    hyperparameters: {
        epochCount: "1",
        batchSize: "1",
        learningRate: "0.005",
        learningRateWarmupSteps: "0",
    },
});
import pulumi
import pulumi_aws as aws

example = aws.bedrockfoundation.get_model(model_id="amazon.titan-text-express-v1")
example_custom_model = aws.bedrock.CustomModel("example",
    output_data_config={
        "s3_uri": f"s3://{output['id']}/data/",
    },
    training_data_config={
        "s3_uri": f"s3://{training['id']}/data/train.jsonl",
    },
    custom_model_name="example-model",
    job_name="example-job-1",
    base_model_identifier=example.model_arn,
    role_arn=example_aws_iam_role["arn"],
    hyperparameters={
        "epochCount": "1",
        "batchSize": "1",
        "learningRate": "0.005",
        "learningRateWarmupSteps": "0",
    })
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = Aws.BedrockFoundation.GetModel.Invoke(new()
    {
        ModelId = "amazon.titan-text-express-v1",
    });

    var exampleCustomModel = new Aws.Bedrock.CustomModel("example", new()
    {
        OutputDataConfig = new Aws.Bedrock.Inputs.CustomModelOutputDataConfigArgs
        {
            S3Uri = $"s3://{output.Id}/data/",
        },
        TrainingDataConfig = new Aws.Bedrock.Inputs.CustomModelTrainingDataConfigArgs
        {
            S3Uri = $"s3://{training.Id}/data/train.jsonl",
        },
        CustomModelName = "example-model",
        JobName = "example-job-1",
        BaseModelIdentifier = example.Apply(getModelResult => getModelResult.ModelArn),
        RoleArn = exampleAwsIamRole.Arn,
        Hyperparameters =
        {
            { "epochCount", "1" },
            { "batchSize", "1" },
            { "learningRate", "0.005" },
            { "learningRateWarmupSteps", "0" },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/bedrock"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/bedrockfoundation"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := bedrockfoundation.GetModel(ctx, &bedrockfoundation.GetModelArgs{
			ModelId: "amazon.titan-text-express-v1",
		}, nil)
		if err != nil {
			return err
		}
		_, err = bedrock.NewCustomModel(ctx, "example", &bedrock.CustomModelArgs{
			OutputDataConfig: &bedrock.CustomModelOutputDataConfigArgs{
				S3Uri: pulumi.Sprintf("s3://%v/data/", output.Id),
			},
			TrainingDataConfig: &bedrock.CustomModelTrainingDataConfigArgs{
				S3Uri: pulumi.Sprintf("s3://%v/data/train.jsonl", training.Id),
			},
			CustomModelName:     pulumi.String("example-model"),
			JobName:             pulumi.String("example-job-1"),
			BaseModelIdentifier: pulumi.String(example.ModelArn),
			RoleArn:             pulumi.Any(exampleAwsIamRole.Arn),
			Hyperparameters: pulumi.StringMap{
				"epochCount":              pulumi.String("1"),
				"batchSize":               pulumi.String("1"),
				"learningRate":            pulumi.String("0.005"),
				"learningRateWarmupSteps": pulumi.String("0"),
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

data "aws_bedrockfoundation_getmodel" "example" {
  model_id = "amazon.titan-text-express-v1"
}

resource "aws_bedrock_custommodel" "example" {
  output_data_config = {
    s3_uri ="s3://${output.id}/data/"
  }
  training_data_config = {
    s3_uri ="s3://${training.id}/data/train.jsonl"
  }
  custom_model_name     = "example-model"
  job_name              = "example-job-1"
  base_model_identifier = data.aws_bedrockfoundation_getmodel.example.model_arn
  role_arn              = exampleAwsIamRole.arn
  hyperparameters = {
    "epochCount"              = "1"
    "batchSize"               = "1"
    "learningRate"            = "0.005"
    "learningRateWarmupSteps" = "0"
  }
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.bedrockfoundation.BedrockfoundationFunctions;
import com.pulumi.aws.bedrockfoundation.inputs.GetModelArgs;
import com.pulumi.aws.bedrock.CustomModel;
import com.pulumi.aws.bedrock.CustomModelArgs;
import com.pulumi.aws.bedrock.inputs.CustomModelOutputDataConfigArgs;
import com.pulumi.aws.bedrock.inputs.CustomModelTrainingDataConfigArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var example = BedrockfoundationFunctions.getModel(GetModelArgs.builder()
            .modelId("amazon.titan-text-express-v1")
            .build());

        var exampleCustomModel = new CustomModel("exampleCustomModel", CustomModelArgs.builder()
            .outputDataConfig(CustomModelOutputDataConfigArgs.builder()
                .s3Uri(String.format("s3://%s/data/", output.id()))
                .build())
            .trainingDataConfig(CustomModelTrainingDataConfigArgs.builder()
                .s3Uri(String.format("s3://%s/data/train.jsonl", training.id()))
                .build())
            .customModelName("example-model")
            .jobName("example-job-1")
            .baseModelIdentifier(example.modelArn())
            .roleArn(exampleAwsIamRole.arn())
            .hyperparameters(Map.ofEntries(
                Map.entry("epochCount", "1"),
                Map.entry("batchSize", "1"),
                Map.entry("learningRate", "0.005"),
                Map.entry("learningRateWarmupSteps", "0")
            ))
            .build());

    }
}
resources:
  exampleCustomModel:
    type: aws:bedrock:CustomModel
    name: example
    properties:
      outputDataConfig:
        s3Uri: s3://${output.id}/data/
      trainingDataConfig:
        s3Uri: s3://${training.id}/data/train.jsonl
      customModelName: example-model
      jobName: example-job-1
      baseModelIdentifier: ${example.modelArn}
      roleArn: ${exampleAwsIamRole.arn}
      hyperparameters:
        epochCount: '1'
        batchSize: '1'
        learningRate: '0.005'
        learningRateWarmupSteps: '0'
variables:
  example:
    fn::invoke:
      function: aws:bedrockfoundation:getModel
      arguments:
        modelId: amazon.titan-text-express-v1

Import

Identity Schema

Required

  • jobArn (String) ARN of the Bedrock custom model job.

Using pulumi import, import Bedrock custom model using the jobArn. For example:

$ pulumi import aws:bedrock/customModel:CustomModel example arn:aws:bedrock:us-west-2:123456789012:model-customization-job/amazon.titan-text-express-v1:0:8k/1y5n57gh5y2e

Constructors

CustomModel(String name, {CustomModelArgs? args, CustomResourceOptions? options})
Creates a new CustomModel. name The Pulumi resource name. args Arguments used to configure this CustomModel. The set of arguments for CustomModel. options Resource options controlling this resource's behavior.
CustomModel.reference(String urn)
Creates a typed reference to an existing CustomModel resource.

Properties

baseModelIdentifier ↔ Output<String>
ARN of the base model.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
customizationType ↔ Output<String>
The customization type. Valid values: FINE_TUNING, CONTINUED_PRE_TRAINING.
latefinal
customModelArn ↔ Output<String>
The ARN of the output model.
latefinal
customModelKmsKeyId ↔ Output<String?>
The custom model is encrypted at rest using this key. Specify the key ARN.
latefinal
customModelName ↔ Output<String>
Name for the custom model.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
hyperparameters ↔ Output<Map<String, String>>
Parameters related to tuning the model.
latefinal
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
jobArn ↔ Output<String>
The ARN of the customization job.
latefinal
jobName ↔ Output<String>
A name for the customization job.
latefinal
jobStatus ↔ Output<String>
The status of the customization job. A successful job transitions from InProgress to Completed when the output model is ready to use.
latefinal
outputDataConfig ↔ Output<CustomModelOutputDataConfig>
S3 location for the output data.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
roleArn ↔ Output<String>
ARN of an IAM role that Bedrock can assume to perform tasks on your behalf.
latefinal
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tags ↔ Output<Map<String, String>?>
A map of tags to assign to the customization job and custom model. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
latefinal
tagsAll ↔ Output<Map<String, String>>
Map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.
latefinal
timeouts ↔ Output<CustomModelTimeouts?>
latefinal
trainingDataConfig ↔ Output<CustomModelTrainingDataConfig>
Information about the training dataset.
latefinal
trainingMetrics ↔ Output<List<CustomModelTrainingMetric>>
Metrics associated with the customization job.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited
validationDataConfig ↔ Output<CustomModelValidationDataConfig?>
Information about the validation dataset.
latefinal
validationMetrics ↔ Output<List<CustomModelValidationMetric>>
The loss metric for each validator that you provided.
latefinal
vpcConfig ↔ Output<CustomModelVpcConfig?>
Configuration parameters for the private VPC that contains the resources you are using for this job.
latefinal

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {CustomModelState? state, CustomResourceOptions? options}) → CustomModel
Gets an existing CustomModel resource's state with the given name and id.