# Secret

A secret environment variable.

- Source: [`aws-batch/lib/ecs-container-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts#L43)
- Type last changed: v2.96.0 · 13 Sep 2023

## Example

```ts
declare const mySecret: secretsmanager.ISecret;

const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
  container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
    image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
    memory: cdk.Size.mebibytes(2048),
    cpu: 256,
    secrets: {
      MY_SECRET_ENV_VAR: batch.Secret.fromSecretsManager(mySecret),
    }
  }),
});
```

## Initializer

```ts
new Secret()
```

## Properties

- `arn`: string — The ARN of the secret.

- `hasField`: boolean — Whether this secret uses a specific JSON field.

## Methods

- `fromSecretsManager(secret: ISecret, field?: string): Secret // chainable` (static) — Creates a environment variable value from a secret stored in AWS Secrets Manager.

  **Parameters**

  - `secret` — the secret stored in AWS Secrets Manager.
  - `field` — the name of the field with the value that you want to set as the environment variable value.

- `fromSecretsManagerVersion(secret: ISecret, versionInfo: SecretVersionInfo, field?: string): Secret // chainable` (static) — Creates a environment variable value from a secret stored in AWS Secrets Manager.

  **Parameters**

  - `secret` — the secret stored in AWS Secrets Manager.
  - `versionInfo` — the version information to reference the secret.
  - `field` — the name of the field with the value that you want to set as the environment variable value.

- `fromSsmParameter(parameter: IParameter): Secret // chainable` (static) — Creates an environment variable value from a parameter stored in AWS Systems Manager Parameter Store.

- `grantRead(grantee: IGrantable): Grant` — Grants reading the secret to a principal [disable-awslint:no-grants].
