ApiKeyCredentialProvider

class aws_cdk.aws_bedrockagentcore.ApiKeyCredentialProvider(scope, id, *, api_key=None, api_key_credential_provider_name=None, tags=None)

Bases: Resource

L2 construct for AWS::BedrockAgentCore::ApiKeyCredentialProvider.

Use this to register an API key identity in AgentCore Token Vault. To attach the identity to a gateway target, use {@link GatewayCredentialProvider.fromApiKeyIdentity } with this construct, or {@link ApiKeyCredentialProvider.bindForGatewayApiKeyTarget} with {@link GatewayCredentialProvider.fromApiKeyIdentityArn }.

See:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-bedrockagentcore-apikeycredentialprovider.html

Resource:

AWS::BedrockAgentCore::ApiKeyCredentialProvider

ExampleMetadata:

infused

Example:

gateway = agentcore.Gateway(self, "MyGateway",
    gateway_name="my-gateway"
)

# Create an API key credential provider in Token Vault
api_key_provider = agentcore.ApiKeyCredentialProvider(self, "MyApiKeyProvider",
    api_key_credential_provider_name="my-apikey"
)

bucket = s3.Bucket.from_bucket_name(self, "ExistingBucket", "my-schema-bucket")
s3my_schema = agentcore.ApiSchema.from_s3_file(bucket, "schemas/myschema.yaml")

# Add an OpenAPI target using the L2 construct directly
target = gateway.add_open_api_target("MyTarget",
    gateway_target_name="my-api-target",
    description="Target for external API integration",
    api_schema=s3my_schema,
    credential_provider_configurations=[
        agentcore.GatewayCredentialProvider.from_api_key_identity(api_key_provider,
            credential_location=agentcore.ApiKeyCredentialLocation.header(
                credential_parameter_name="X-API-Key"
            )
        )
    ]
)

# This makes sure your s3 bucket is available before target
target.node.add_dependency(bucket)
Parameters:
  • scope (Construct)

  • id (str)

  • api_key (Optional[SecretValue]) – The API key value. NOTE: The API key will be included in the CloudFormation template as part of synthesis. The service stores the key in Secrets Manager after creation, but the value is visible in the template and deployment history. Use SecretValue.unsafePlainText() to explicitly acknowledge plaintext, or pass a reference from another construct to avoid embedding the literal value. If omitted, you can supply the key through another mechanism supported by the service. Default: - no key in template (provider may still be created depending on service behavior)

  • api_key_credential_provider_name (Optional[str]) – Name of the credential provider. Default: a name generated by CDK

  • tags (Optional[Mapping[str, str]]) – Tags for this credential provider. Default: - no tags

Methods

apply_removal_policy(policy)

Apply the given removal policy to this resource.

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).

Parameters:

policy (RemovalPolicy)

Return type:

None

bind_for_gateway_api_key_target()

ARNs for {@link GatewayCredentialProvider.fromApiKeyIdentity } / {@link GatewayCredentialProvider.fromApiKeyIdentityArn }.

Return type:

GatewayApiKeyIdentityBinding

grant(grantee, *actions)

[disable-awslint:no-grants].

Parameters:
Return type:

Grant

grant_admin(grantee)

[disable-awslint:no-grants].

Parameters:

grantee (IGrantable)

Return type:

Grant

grant_full_access(grantee)

[disable-awslint:no-grants].

Parameters:

grantee (IGrantable)

Return type:

Grant

grant_read(grantee)

[disable-awslint:no-grants].

Parameters:

grantee (IGrantable)

Return type:

Grant

grant_use(grantee)

[disable-awslint:no-grants].

Parameters:

grantee (IGrantable)

Return type:

Grant

to_string()

Returns a string representation of this construct.

Return type:

str

with_(*mixins)

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.

Parameters:

mixins (IMixin)

Return type:

IConstruct

Attributes

PROPERTY_INJECTION_ID = 'aws-cdk-lib.aws-bedrockagentcore.ApiKeyCredentialProvider'
api_key_credential_provider_name

The name of this API key credential provider.

Attribute:

true

api_key_credential_provider_ref

A reference to a ApiKeyCredentialProvider resource.

api_key_secret_arn

The ARN of the Secrets Manager secret that stores the API key after the resource is created.

May be undefined for resources imported without this attribute.

created_time

Timestamp when the credential provider was created.

credential_provider_arn

The ARN of this credential provider.

env

The environment this resource belongs to.

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.

grant_principal

The principal to grant permissions to.

last_updated_time

Timestamp when the credential provider was last updated.

node

The tree node.

stack

The stack in which this resource is defined.

Static Methods

classmethod from_api_key_credential_provider_attributes(scope, id, *, credential_provider_arn, api_key_secret_arn=None, created_time=None, last_updated_time=None)

Import an existing API key credential provider.

Parameters:
  • scope (Construct)

  • id (str)

  • credential_provider_arn (str) – ARN of the credential provider.

  • api_key_secret_arn (Optional[str]) – ARN of the Secrets Manager secret for the API key, if known. Default: - not set; required for {@link ApiKeyCredentialProvider.bindForGatewayApiKeyTarget } on imported providers

  • created_time (Optional[str]) – Resource creation time. Default: - not set

  • last_updated_time (Optional[str]) – Resource last-updated time. Default: - not set

Return type:

IApiKeyCredentialProvider

classmethod is_construct(x)

Checks if x is a construct.

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:

x (Any) – Any object.

Return type:

bool

Returns:

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

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct)

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct)

Return type:

bool