# Connection

An AWS Glue connection to a data source.

Extends: Construct › Resource › Connection
Implements: IResource, IConnection, IEnvironmentAware, IConstruct, IDependable

- CloudFormation: [`AWS::Glue::Connection`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-glue-connection.html)
- L1 type: [`CfnConnection`](/cdk/api/v2/docs/aws-cdk-lib.aws_glue.CfnConnection.html)
- Source: [`aws-glue/lib/connection.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-glue/lib/connection.ts#L393)
- Type last changed: v2.270.0 · 17 Sep 2026

## Example

```ts
import * as cdk from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
declare const stack: cdk.Stack;
declare const role: iam.IRole;
declare const script: glue.Code;
new glue.PySparkEtlJob(stack, 'PySparkETLJob', {
  jobName: 'PySparkETLJobCustomName',
  description: 'This is a description',
  role,
  script,
  glueVersion: glue.GlueVersion.V6_0,
  continuousLogging: { enabled: false },
  workerConfiguration: {
    workerType: glue.WorkerType.G_2X,
    numberOfWorkers: 2,
  },
  maxConcurrentRuns: 100,
  timeout: cdk.Duration.hours(2),
  connections: [glue.Connection.fromConnectionName(stack, 'Connection', 'connectionName')],
  securityConfiguration: glue.SecurityConfiguration.fromSecurityConfigurationName(stack, 'SecurityConfig', 'securityConfigName'),
  tags: {
    FirstTagName: 'FirstTagValue',
    SecondTagName: 'SecondTagValue',
    XTagName: 'XTagValue',
  },
  maxRetries: 2,
});
```

## Initializer

```ts
new Connection(scope: Construct, id: string, props: ConnectionProps)
```

## Construct Props

- `connectionName`: string — The name of the connection.

  **Default:** cloudformation generated name

- `description`: string — The description of the connection.

  **Default:** no description

- `matchCriteria`: string[] — A list of criteria that can be used in selecting this connection.

  **Default:** no match criteria

  This is useful for filtering the results of https://awscli.amazonaws.com/v2/documentation/api/latest/reference/glue/get-connections.html

- `network`: [ConnectionNetwork](/cdk/api/v2/docs/aws-cdk-lib.aws_glue.ConnectionNetwork.html) — The VPC network placement for this connection, so it can reach resources inside a VPC. See more at https://docs.aws.amazon.com/glue/latest/dg/start-connecting.html.

  **Default:** no VPC network placement

  Build it with `ConnectionNetwork.subnet(subnet)` to pin a specific subnet,
  or `ConnectionNetwork.vpc(vpc, vpcSubnets?)` to let the CDK select one.

- `properties`: { [key: string]: string } — Key-Value pairs that define parameters for the connection.

  **Default:** empty properties

- `secret`: [ISecretRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_secretsmanager.ISecretRef.html) — A reference to a Secrets Manager secret holding the credentials for this connection.

  **Default:** no secret; any credentials must be supplied via `properties`

  The secret is referenced through the connection's `SECRET_ID` property, so
  Glue reads the credentials at runtime and the secret value never appears in
  the synthesized template. Prefer this over placing credentials directly in
  `properties`. Accepts any `secretsmanager.ISecret`.

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The list of security groups needed to successfully make this connection e.g. to successfully connect to VPC.

  **Default:** no security group

- `type`: [ConnectionType](/cdk/api/v2/docs/aws-cdk-lib.aws_glue.ConnectionType.html) (required) — The type of the connection.

## Properties

- `connectionArn`: string — The ARN of the connection.

- `connectionName`: string — The name of the connection.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

## Methods

- `addProperty(key: string, value: string): void` — Add additional connection parameters.

  **Parameters**

  - `key` — parameter key.
  - `value` — parameter value.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromConnectionArn(scope: Construct, id: string, connectionArn: string): IConnection` (static) — Creates a Connection construct that represents an external connection.

  **Parameters**

  - `scope` — The scope creating construct (usually `this`).
  - `id` — The construct's id.
  - `connectionArn` — arn of external connection.

- `fromConnectionName(scope: Construct, id: string, connectionName: string): IConnection` (static) — Creates a Connection construct that represents an external connection.

  **Parameters**

  - `scope` — The scope creating construct (usually `this`).
  - `id` — The construct's id.
  - `connectionName` — name of external connection.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
