class Secret
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ECS.Secret |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsecs#Secret |
Java | software.amazon.awscdk.services.ecs.Secret |
Python | aws_cdk.aws_ecs.Secret |
TypeScript (source) | aws-cdk-lib » aws_ecs » Secret |
A secret environment variable.
Example
declare const secret: secretsmanager.Secret;
declare const parameter: ssm.StringParameter;
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('TheContainer', {
image: ecs.ContainerImage.fromRegistry('example-image'),
memoryLimitMiB: 256,
logging: ecs.LogDrivers.firelens({
options: {
// ... log driver options here ...
},
secretOptions: { // Retrieved from AWS Secrets Manager or AWS Systems Manager Parameter Store
apikey: ecs.Secret.fromSecretsManager(secret),
host: ecs.Secret.fromSsmParameter(parameter),
},
}),
});
Initializer
new Secret()
Properties
Name | Type | Description |
---|---|---|
arn | string | The ARN of the secret. |
has | boolean | Whether this secret uses a specific JSON field. |
arn
Type:
string
The ARN of the secret.
hasField?
Type:
boolean
(optional)
Whether this secret uses a specific JSON field.
Methods
Name | Description |
---|---|
grant | Grants reading the secret to a principal. |
static from | Creates a environment variable value from a secret stored in AWS Secrets Manager. |
static from | Creates a environment variable value from a secret stored in AWS Secrets Manager. |
static from | Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store. |
Read(grantee)
grantpublic grantRead(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grants reading the secret to a principal.
SecretsManager(secret, field?)
static frompublic static fromSecretsManager(secret: ISecret, field?: string): Secret
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
Creates a environment variable value from a secret stored in AWS Secrets Manager.
SecretsManagerVersion(secret, versionInfo, field?)
static frompublic static fromSecretsManagerVersion(secret: ISecret, versionInfo: SecretVersionInfo, field?: string): Secret
Parameters
- secret
ISecret
— the secret stored in AWS Secrets Manager. - versionInfo
Secret
— the version information to reference the secret.Version Info - field
string
— the name of the field with the value that you want to set as the environment variable value.
Returns
Creates a environment variable value from a secret stored in AWS Secrets Manager.
SsmParameter(parameter)
static frompublic static fromSsmParameter(parameter: IParameter): Secret
Parameters
- parameter
IParameter
Returns
Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store.