# CfnMapping

Represents a CloudFormation mapping.

Extends: Construct › CfnElement › CfnRefElement › CfnMapping
Implements: IConstruct, IDependable

- Source: [`core/lib/cfn-mapping.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/core/lib/cfn-mapping.ts#L42)
- Type last changed: v2.91.0 · 10 Aug 2023

## Example

```ts
const regionTable = new CfnMapping(this, 'RegionTable', {
  mapping: {
    'us-east-1': {
      regionName: 'US East (N. Virginia)',
      // ...
    },
    'us-east-2': {
      regionName: 'US East (Ohio)',
      // ...
    },
    // ...
  }
});

regionTable.findInMap(Aws.REGION, 'regionName')
```

## Initializer

```ts
new CfnMapping(scope: Construct, id: string, props?: CfnMappingProps)
```

## Construct Props

- `lazy`: boolean

- `mapping`: { [key: string]: { [key: string]: any } } — Mapping of key to a set of corresponding set of named values.

  **Default:** No mapping.

  The key identifies a map of name-value pairs and must be unique within the mapping.

  For example, if you want to set values based on a region, you can create a mapping
  that uses the region name as a key and contains the values you want to specify for
  each specific region.

## Properties

- `creationStack`: string[]

- `logicalId`: string — The logical ID for this CloudFormation stack element.

  The logical ID of the element
  is calculated from the path of the resource node in the construct tree.

  To override this value, use `overrideLogicalId(newLogicalId)`.

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

- `ref`: string — Return a string that will be resolved to a CloudFormation `{ Ref }` for this element.

  If, by any chance, the intrinsic reference of a resource is not a string, you could
  coerce it to an IResolvable through `Lazy.any({ produce: resource.ref })`.

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

  CfnElements must be defined within a stack scope (directly or indirectly).

## Methods

- `findInMap(key1: string, key2: string, defaultValue?: string): string`

  **Returns:** A reference to a value in the map based on the two keys. If mapping is lazy, the value from the map or default value is returned instead of the reference and the mapping is not rendered in the template.

- `isCfnElement(x: any): boolean` (static) — Returns `true` if a construct is a stack element (i.e. part of the synthesized cloudformation template).

  Uses duck-typing instead of `instanceof` to allow stack elements from different
  versions of this library to be included in the same stack.

  **Returns:** The construct as a stack element or undefined if it is not a stack element.

- `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`.

- `overrideLogicalId(newLogicalId: string): void` — Overrides the auto-generated logical ID with a specific ID.

  **Parameters**

  - `newLogicalId` — The new logical ID to use for this stack element.

- `setValue(key1: string, key2: string, value: any): void` — Sets a value in the map based on the two keys.

- `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.
