class EnvironmentFile
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ECS.EnvironmentFile |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsecs#EnvironmentFile |
Java | software.amazon.awscdk.services.ecs.EnvironmentFile |
Python | aws_cdk.aws_ecs.EnvironmentFile |
TypeScript (source) | aws-cdk-lib » aws_ecs » EnvironmentFile |
Implemented by
Asset
, S3
Constructs for types of environment files.
Example
declare const secret: secretsmanager.Secret;
declare const dbSecret: secretsmanager.Secret;
declare const parameter: ssm.StringParameter;
declare const taskDefinition: ecs.TaskDefinition;
declare const s3Bucket: s3.Bucket;
const newContainer = taskDefinition.addContainer('container', {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
memoryLimitMiB: 1024,
environment: { // clear text, not for sensitive data
STAGE: 'prod',
},
environmentFiles: [ // list of environment files hosted either on local disk or S3
ecs.EnvironmentFile.fromAsset('./demo-env-file.env'),
ecs.EnvironmentFile.fromBucket(s3Bucket, 'assets/demo-env-file.env'),
],
secrets: { // Retrieved from AWS Secrets Manager or AWS Systems Manager Parameter Store at container start-up.
SECRET: ecs.Secret.fromSecretsManager(secret),
DB_PASSWORD: ecs.Secret.fromSecretsManager(dbSecret, 'password'), // Reference a specific JSON field, (requires platform version 1.4.0 or later for Fargate tasks)
API_KEY: ecs.Secret.fromSecretsManagerVersion(secret, { versionId: '12345' }, '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: ecs.Secret.fromSsmParameter(parameter),
},
});
newContainer.addEnvironment('QUEUE_NAME', 'MyQueue');
newContainer.addSecret('API_KEY', ecs.Secret.fromSecretsManager(secret));
newContainer.addSecret('DB_PASSWORD', ecs.Secret.fromSecretsManager(secret, 'password'));
Initializer
new EnvironmentFile()
Methods
Name | Description |
---|---|
bind(scope) | Called when the container is initialized to allow this object to bind to the stack. |
static from | Loads the environment file from a local disk path. |
static from | Loads the environment file from an S3 bucket. |
bind(scope)
public bind(scope: Construct): EnvironmentFileConfig
Parameters
- scope
Construct
— The binding scope.
Returns
Called when the container is initialized to allow this object to bind to the stack.
Asset(path, options?)
static frompublic static fromAsset(path: string, options?: AssetOptions): AssetEnvironmentFile
Parameters
- path
string
— Local disk path. - options
Asset
Options
Returns
Loads the environment file from a local disk path.
Bucket(bucket, key, objectVersion?)
static frompublic static fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3EnvironmentFile
Parameters
- bucket
IBucket
— The S3 bucket. - key
string
— The object key. - objectVersion
string
— Optional S3 object version.
Returns
Loads the environment file from an S3 bucket.