Skip to content
v2.274.0

Experimental

@aws-cdk/aws-bedrock-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

Prompt L1 construct ​

Class to create (or import) a Prompt with CDK.

Prompts are a specific set of inputs that guide Foundation Models (FMs) on Amazon Bedrock to generate an appropriate response or output for a given task or instruction. You can optimize the prompt for specific use cases and models.

Example ​

ts
const cmk = new kms.Key(this, 'cmk', {});
const claudeModel = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

const variant1 = bedrock.PromptVariant.text({
  variantName: 'variant1',
  model: claudeModel,
  promptVariables: ['topic'],
  promptText: 'This is my first text prompt. Please summarize our conversation on: {{topic}}.',
  inferenceConfiguration: bedrock.PromptInferenceConfiguration.text({
    temperature: 1.0,
    topP: 0.999,
    maxTokens: 2000,
  }),
});

const prompt1 = new bedrock.Prompt(this, 'prompt1', {
  promptName: 'prompt1',
  description: 'my first prompt',
  defaultVariant: variant1,
  variants: [variant1],
  kmsKey: cmk,
});
python
cmk = kms.Key(self, "cmk")
claude_model = bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0

variant1 = bedrock.PromptVariant.text(
    variant_name="variant1",
    model=claude_model,
    prompt_variables=["topic"],
    prompt_text="This is my first text prompt. Please summarize our conversation on: {{topic}}.",
    inference_configuration=bedrock.PromptInferenceConfiguration.text(
        temperature=1,
        top_p=0.999,
        max_tokens=2000
    )
)

prompt1 = bedrock.Prompt(self, "prompt1",
    prompt_name="prompt1",
    description="my first prompt",
    default_variant=variant1,
    variants=[variant1],
    kms_key=cmk
)
java
Key cmk = Key.Builder.create(this, "cmk").build();
BedrockFoundationModel claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

IPromptVariant variant1 = PromptVariant.text(TextPromptVariantProps.builder()
        .variantName("variant1")
        .model(claudeModel)
        .promptVariables(List.of("topic"))
        .promptText("This is my first text prompt. Please summarize our conversation on: {{topic}}.")
        .inferenceConfiguration(PromptInferenceConfiguration.text(PromptInferenceConfigurationProps.builder()
                .temperature(1)
                .topP(0.999)
                .maxTokens(2000)
                .build()))
        .build());

Prompt prompt1 = Prompt.Builder.create(this, "prompt1")
        .promptName("prompt1")
        .description("my first prompt")
        .defaultVariant(variant1)
        .variants(List.of(variant1))
        .kmsKey(cmk)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Alpha
var cmk = new Key(this, "cmk", new KeyProps { });
var claudeModel = BedrockFoundationModel.ANTHROPIC_CLAUDE_SONNET_V1_0;

var variant1 = PromptVariant.Text(new TextPromptVariantProps {
    VariantName = "variant1",
    Model = claudeModel,
    PromptVariables = new [] { "topic" },
    PromptText = "This is my first text prompt. Please summarize our conversation on: {{topic}}.",
    InferenceConfiguration = PromptInferenceConfiguration.Text(new PromptInferenceConfigurationProps {
        Temperature = 1,
        TopP = 0.999,
        MaxTokens = 2000
    })
});

var prompt1 = new Prompt(this, "prompt1", new PromptProps {
    PromptName = "prompt1",
    Description = "my first prompt",
    DefaultVariant = variant1,
    Variants = new [] { variant1 },
    KmsKey = cmk
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockalpha/v2
cmk := kms.NewKey(this, jsii.String("cmk"), &KeyProps{
})
claudeModel := bedrock.BedrockFoundationModel_ANTHROPIC_CLAUDE_SONNET_V1_0()

variant1 := bedrock.PromptVariant_Text(&TextPromptVariantProps{
	VariantName: jsii.String("variant1"),
	Model: claudeModel,
	PromptVariables: []*string{
		jsii.String("topic"),
	},
	PromptText: jsii.String("This is my first text prompt. Please summarize our conversation on: {{topic}}."),
	InferenceConfiguration: bedrock.PromptInferenceConfiguration_Text(&PromptInferenceConfigurationProps{
		Temperature: jsii.Number(1),
		TopP: jsii.Number(0.999),
		MaxTokens: jsii.Number(2000),
	}),
})

prompt1 := bedrock.NewPrompt(this, jsii.String("prompt1"), &PromptProps{
	PromptName: jsii.String("prompt1"),
	Description: jsii.String("my first prompt"),
	DefaultVariant: variant1,
	Variants: []IPromptVariant{
		variant1,
	},
	KmsKey: cmk,
})

Initializer ​

ts
new Prompt(scope: Construct, id: string, props: PromptProps)
python
Prompt(scope: Construct, id: str, props: PromptProps)
java
new Prompt(Construct scope, String id, PromptProps props)
csharp
new Prompt(Construct scope, string id, PromptProps props)
go
NewPrompt(Scope Construct, Id *string, Props PromptProps)

Construct Props ​

defaultVariantIPromptVariantdefault_variantIPromptVariantdefaultVariantIPromptVariantDefaultVariantIPromptVariantDefaultVariantIPromptVariant= No default variant provided.#
The Prompt Variant that will be used by default.
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description provided. Maximum…#
A description of what the prompt does.
default

Default: No description provided. Maximum Length: 200

kmsKeyIKeykms_keyIKeykmsKeyIKeyKmsKeyIKeyKmsKeyIKey= AWS owned and managed key.#
The KMS key that the prompt is encrypted with.
promptNamestringprompt_namestrpromptNameStringPromptNamestringPromptName*stringrequired#
The name of the prompt.

This will be used as the physical name of the prompt. Allowed Pattern: ^([0-9a-zA-Z][_-]?){1,100}$

tags{ [key: string]: string }tagstyping.Mapping[str, str]tagsMap<String, String>TagsIDictionary<string, string>Tags*map[string]*string= No tags applied.#
Tags to apply to the prompt.
variantsIPromptVariant[]variantstyping.List[IPromptVariant]variantsList<IPromptVariant>VariantsIPromptVariant[]Variants*[]IPromptVariant= No additional variants provided.#
The variants of your prompt.

Variants can use different messages, models, or configurations so that you can compare their outputs to decide the best variant for your use case. Maximum of 1 variants.

Properties ​

descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string#
The description of the prompt.
The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

kmsKeyIKeykms_keyIKeykmsKeyIKeyKmsKeyIKeyKmsKeyIKey#
The KMS key that the prompt is encrypted with.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
promptArnstringprompt_arnstrpromptArnStringPromptArnstringPromptArn*stringrequired#
The ARN of the prompt.
example
ts
"arn:aws:bedrock:us-east-1:123456789012:prompt/PROMPT12345"
promptIdstringprompt_idstrpromptIdStringPromptIdstringPromptId*stringrequired#
The ID of the prompt.
example
ts
"PROMPT12345"
promptNamestringprompt_namestrpromptNameStringPromptNamestringPromptName*stringrequired#
The name of the prompt.
promptVersionstringprompt_versionstrpromptVersionStringPromptVersionstringPromptVersion*stringrequired#
The version of the prompt.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
variantsIPromptVariant[]variantstyping.List[IPromptVariant]variantsList<IPromptVariant>VariantsIPromptVariant[]Variants*[]IPromptVariantrequired#
The variants of the prompt.

Methods ​

addVariant(variant: IPromptVariant): voiddef add_variant(self, variant: IPromptVariant) -> Nonepublic void addVariant(IPromptVariant variant)public void AddVariant(IPromptVariant variant)func AddVariant(Variant IPromptVariant)#
Adds a prompt variant to the prompt.
1 parameter

Parameters

  • variantvariantvariantvariantVariant — - The prompt variant to add.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

createVersion(description?: string): PromptVersiondef create_version(self, description: typing.Optional[str] = None) -> PromptVersionpublic PromptVersion createVersion(String description)public PromptVersion CreateVersion(string? description = null)func CreateVersion(Description *string) PromptVersion#
Creates a prompt version, a static snapshot of your prompt that can be deployed to production.
1 parameter · returns

Parameters

  • descriptiondescriptiondescriptiondescriptionDescription — - Optional description for the version.

Returns: A PromptVersion object containing the version details including ARN and version string

fromPromptAttributes(scope: Construct, id: string, attrs: PromptAttributes): IPrompt@staticmethod def from_prompt_attributes(scope: Construct, id: str, attrs: PromptAttributes) -> IPromptpublic static IPrompt fromPromptAttributes(Construct scope, String id, PromptAttributes attrs)public static IPrompt FromPromptAttributes(Construct scope, string id, PromptAttributes attrs)func FromPromptAttributes(Scope Construct, Id *string, Attrs PromptAttributes) IPromptstatic#
Creates a Prompt reference from an existing prompt's attributes.
3 parameters · returns

Parameters

  • scopescopescopescopeScope — - The construct scope.
  • ididididId — - Identifier of the construct.
  • attrsattrsattrsattrsAttrs — - Attributes of the existing prompt.

Returns: An IPrompt reference to the existing prompt

grantGet(grantee: IGrantable): Grantdef grant_get(self, grantee: IGrantable) -> Grantpublic Grant grantGet(IGrantable grantee)public Grant GrantGet(IGrantable grantee)func GrantGet(Grantee IGrantable) Grant#
Grant the given identity permissions to get the prompt.

[disable-awslint:no-grants]

1 parameter · returns

Parameters

  • granteegranteegranteegranteeGrantee — - The IAM principal to grant permissions to.

Returns: An IAM Grant object representing the granted permissions

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.