Secret

class aws_cdk.aws_batch.Secret

Bases: object

A secret environment variable.

ExampleMetadata:

infused

Example:

# my_secret: secretsmanager.ISecret


job_defn = batch.EcsJobDefinition(self, "JobDefn",
    container=batch.EcsEc2ContainerDefinition(self, "containerDefn",
        image=ecs.ContainerImage.from_registry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
        memory=cdk.Size.mebibytes(2048),
        cpu=256,
        secrets={
            "MY_SECRET_ENV_VAR": batch.Secret.from_secrets_manager(my_secret)
        }
    )
)

Methods

abstract grant_read(grantee)

Grants reading the secret to a principal.

Parameters:

grantee (IGrantable) –

Return type:

Grant

Attributes

arn

The ARN of the secret.

has_field

Whether this secret uses a specific JSON field.

Static Methods

classmethod from_secrets_manager(secret, field=None)

Creates a environment variable value from a secret stored in AWS Secrets Manager.

Parameters:
  • secret (ISecret) – the secret stored in AWS Secrets Manager.

  • field (Optional[str]) – the name of the field with the value that you want to set as the environment variable value. Only values in JSON format are supported. If you do not specify a JSON field, then the full content of the secret is used.

Return type:

Secret

classmethod from_secrets_manager_version(secret, version_info, field=None)

Creates a environment variable value from a secret stored in AWS Secrets Manager.

Parameters:
  • secret (ISecret) – the secret stored in AWS Secrets Manager.

  • version_info (Union[SecretVersionInfo, Dict[str, Any]]) – the version information to reference the secret.

  • field (Optional[str]) – the name of the field with the value that you want to set as the environment variable value. Only values in JSON format are supported. If you do not specify a JSON field, then the full content of the secret is used.

Return type:

Secret

classmethod from_ssm_parameter(parameter)

Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store.

Parameters:

parameter (IParameter) –

Return type:

Secret