Class Secret
A secret environment variable.
Namespace: Amazon.CDK.AWS.ECS
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class Secret : DeputyBase
Syntax (vb)
Public MustInherit Class Secret Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
Secret secret;
StringParameter parameter;
var taskDefinition = new Ec2TaskDefinition(this, "TaskDef");
taskDefinition.AddContainer("TheContainer", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("example-image"),
MemoryLimitMiB = 256,
Logging = LogDrivers.Firelens(new FireLensLogDriverProps {
Options = new Dictionary<string, object> { },
SecretOptions = new Dictionary<string, Secret> { // Retrieved from AWS Secrets Manager or AWS Systems Manager Parameter Store
{ "apikey", Secret.FromSecretsManager(secret) },
{ "host", Secret.FromSsmParameter(parameter) } }
})
});
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
Secret secret;
StringParameter parameter;
var taskDefinition = new Ec2TaskDefinition(this, "TaskDef");
taskDefinition.AddContainer("TheContainer", new ContainerDefinitionOptions {
Image = ContainerImage.FromRegistry("example-image"),
MemoryLimitMiB = 256,
Logging = LogDrivers.Firelens(new FireLensLogDriverProps {
Options = new Dictionary<string, object> { },
SecretOptions = new Dictionary<string, Secret> { // Retrieved from AWS Secrets Manager or AWS Systems Manager Parameter Store
{ "apikey", Secret.FromSecretsManager(secret) },
{ "host", Secret.FromSsmParameter(parameter) } }
})
});
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
[disable-awslint:no-grants]