Class Secret

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.ecs.Secret
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:47.443Z") @Stability(Stable) public abstract class Secret extends software.amazon.jsii.JsiiObject
A secret environment variable.

Example:

 Secret secret;
 Secret dbSecret;
 StringParameter parameter;
 TaskDefinition taskDefinition;
 Bucket s3Bucket;
 ContainerDefinition newContainer = taskDefinition.addContainer("container", ContainerDefinitionOptions.builder()
         .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
         .memoryLimitMiB(1024)
         .environment(Map.of( // clear text, not for sensitive data
                 "STAGE", "prod"))
         .environmentFiles(List.of(EnvironmentFile.fromAsset("./demo-env-file.env"), EnvironmentFile.fromBucket(s3Bucket, "assets/demo-env-file.env")))
         .secrets(Map.of( // Retrieved from AWS Secrets Manager or AWS Systems Manager Parameter Store at container start-up.
                 "SECRET", Secret.fromSecretsManager(secret),
                 "DB_PASSWORD", Secret.fromSecretsManager(dbSecret, "password"),  // Reference a specific JSON field, (requires platform version 1.4.0 or later for Fargate tasks)
                 "API_KEY", Secret.fromSecretsManagerVersion(secret, SecretVersionInfo.builder().versionId("12345").build(), "apiKey"),  // Reference a specific version of the secret by its version id or version stage (requires platform version 1.4.0 or later for Fargate tasks)
                 "PARAMETER", Secret.fromSsmParameter(parameter)))
         .build());
 newContainer.addEnvironment("QUEUE_NAME", "MyQueue");
 
  • Nested Class Summary

    Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject

    software.amazon.jsii.JsiiObject.InitializationMode
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    Secret(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
     
    protected
    Secret(software.amazon.jsii.JsiiObjectRef objRef)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Secret
    Creates a environment variable value from a secret stored in AWS Secrets Manager.
    static Secret
    Creates a environment variable value from a secret stored in AWS Secrets Manager.
    static Secret
    Creates a environment variable value from a secret stored in AWS Secrets Manager.
    static Secret
    Creates a environment variable value from a secret stored in AWS Secrets Manager.
    static Secret
    Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store.
    abstract String
    The ARN of the secret.
    abstract Boolean
    Whether this secret uses a specific JSON field.
    abstract Grant
    Grants reading the secret to a principal.

    Methods inherited from class software.amazon.jsii.JsiiObject

    jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface software.amazon.jsii.JsiiSerializable

    $jsii$toJson
  • Constructor Details

    • Secret

      protected Secret(software.amazon.jsii.JsiiObjectRef objRef)
    • Secret

      protected Secret(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Secret

      @Stability(Stable) protected Secret()
  • Method Details

    • fromSecretsManager

      @Stability(Stable) @NotNull public static Secret fromSecretsManager(@NotNull ISecret secret, @Nullable String field)
      Creates a environment variable value from a secret stored in AWS Secrets Manager.

      Parameters:
      secret - the secret stored in AWS Secrets Manager. This parameter is required.
      field - the name of the field with the value that you want to set as the environment variable value.
    • fromSecretsManager

      @Stability(Stable) @NotNull public static Secret fromSecretsManager(@NotNull ISecret secret)
      Creates a environment variable value from a secret stored in AWS Secrets Manager.

      Parameters:
      secret - the secret stored in AWS Secrets Manager. This parameter is required.
    • fromSecretsManagerVersion

      @Stability(Stable) @NotNull public static Secret fromSecretsManagerVersion(@NotNull ISecret secret, @NotNull SecretVersionInfo versionInfo, @Nullable String field)
      Creates a environment variable value from a secret stored in AWS Secrets Manager.

      Parameters:
      secret - the secret stored in AWS Secrets Manager. This parameter is required.
      versionInfo - the version information to reference the secret. This parameter is required.
      field - the name of the field with the value that you want to set as the environment variable value.
    • fromSecretsManagerVersion

      @Stability(Stable) @NotNull public static Secret fromSecretsManagerVersion(@NotNull ISecret secret, @NotNull SecretVersionInfo versionInfo)
      Creates a environment variable value from a secret stored in AWS Secrets Manager.

      Parameters:
      secret - the secret stored in AWS Secrets Manager. This parameter is required.
      versionInfo - the version information to reference the secret. This parameter is required.
    • fromSsmParameter

      @Stability(Stable) @NotNull public static Secret fromSsmParameter(@NotNull IParameter parameter)
      Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store.

      Parameters:
      parameter - This parameter is required.
    • grantRead

      @Stability(Stable) @NotNull public abstract Grant grantRead(@NotNull IGrantable grantee)
      Grants reading the secret to a principal.

      Parameters:
      grantee - This parameter is required.
    • getArn

      @Stability(Stable) @NotNull public abstract String getArn()
      The ARN of the secret.
    • getHasField

      @Stability(Stable) @Nullable public abstract Boolean getHasField()
      Whether this secret uses a specific JSON field.