Class Secret
A secret environment variable.
Namespace: Amazon.CDK.AWS.Batch
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class Secret : DeputyBase
Syntax (vb)
Public MustInherit Class Secret Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
ISecret mySecret;
var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
Container = new EcsEc2ContainerDefinition(this, "containerDefn", new EcsEc2ContainerDefinitionProps {
Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
Memory = Size.Mebibytes(2048),
Cpu = 256,
Secrets = new Dictionary<string, Secret> {
{ "MY_SECRET_ENV_VAR", Secret.FromSecretsManager(mySecret) }
}
})
});
Synopsis
Constructors
| Secret() | A secret environment variable. |
Properties
| Arn | The ARN of the secret. |
| HasField | Whether this secret uses a specific JSON field. |
Methods
| FromSecretsManager(ISecret, string?) | Creates a environment variable value from a secret stored in AWS Secrets Manager. |
| FromSecretsManagerVersion(ISecret, ISecretVersionInfo, string?) | Creates a environment variable value from a secret stored in AWS Secrets Manager. |
| FromSsmParameter(IParameter) | Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store. |
| GrantRead(IGrantable) | Grants reading the secret to a principal. |
Constructors
Secret()
A secret environment variable.
protected Secret()
Remarks
ExampleMetadata: infused
Examples
ISecret mySecret;
var jobDefn = new EcsJobDefinition(this, "JobDefn", new EcsJobDefinitionProps {
Container = new EcsEc2ContainerDefinition(this, "containerDefn", new EcsEc2ContainerDefinitionProps {
Image = ContainerImage.FromRegistry("public.ecr.aws/amazonlinux/amazonlinux:latest"),
Memory = Size.Mebibytes(2048),
Cpu = 256,
Secrets = new Dictionary<string, Secret> {
{ "MY_SECRET_ENV_VAR", Secret.FromSecretsManager(mySecret) }
}
})
});
Properties
Arn
The ARN of the secret.
public abstract string Arn { get; }
Property Value
Remarks
ExampleMetadata: infused
HasField
Whether this secret uses a specific JSON field.
public abstract bool? HasField { get; }
Property Value
bool?
Remarks
ExampleMetadata: infused
Methods
FromSecretsManager(ISecret, string?)
Creates a environment variable value from a secret stored in AWS Secrets Manager.
public static Secret FromSecretsManager(ISecret secret, string? field = null)
Parameters
- secret ISecret
the secret stored in AWS Secrets Manager.
- field string
the name of the field with the value that you want to set as the environment variable value.
Returns
Remarks
ExampleMetadata: infused
FromSecretsManagerVersion(ISecret, ISecretVersionInfo, string?)
Creates a environment variable value from a secret stored in AWS Secrets Manager.
public static Secret FromSecretsManagerVersion(ISecret secret, ISecretVersionInfo versionInfo, string? field = null)
Parameters
- secret ISecret
the secret stored in AWS Secrets Manager.
- versionInfo ISecretVersionInfo
the version information to reference the secret.
- field string
the name of the field with the value that you want to set as the environment variable value.
Returns
Remarks
ExampleMetadata: infused
FromSsmParameter(IParameter)
Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store.
public static Secret FromSsmParameter(IParameter parameter)
Parameters
- parameter IParameter
Returns
Remarks
ExampleMetadata: infused
GrantRead(IGrantable)
Grants reading the secret to a principal.
public abstract Grant GrantRead(IGrantable grantee)
Parameters
- grantee IGrantable
Returns
Remarks
ExampleMetadata: infused