Skip to content
v2.274.0

CfnMapping L1 construct ​

Represents a CloudFormation mapping.

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')
python
region_table = CfnMapping(self, "RegionTable",
    mapping={
        "us-east-1": {
            "region_name": "US East (N. Virginia)"
        },
        "us-east-2": {
            "region_name": "US East (Ohio)"
        }
    }
)

region_table.find_in_map(Aws.REGION, "regionName")
java
CfnMapping regionTable = CfnMapping.Builder.create(this, "RegionTable")
        .mapping(Map.of(
                "us-east-1", Map.of(
                        "regionName", "US East (N. Virginia)"),
                "us-east-2", Map.of(
                        "regionName", "US East (Ohio)")))
        .build();

regionTable.findInMap(Aws.REGION, "regionName");
csharp
// Install: dotnet add package Amazon.CDK.Lib
var regionTable = new CfnMapping(this, "RegionTable", new CfnMappingProps {
    Mapping = new Dictionary<string, IDictionary<string, object>> {
        { "us-east-1", new Dictionary<string, object> {
            { "regionName", "US East (N. Virginia)" }
        } },
        { "us-east-2", new Dictionary<string, object> {
            { "regionName", "US East (Ohio)" }
        } }
    }
});

regionTable.FindInMap(Aws.REGION, "regionName");
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
regionTable := awscdk.NewCfnMapping(this, jsii.String("RegionTable"), &CfnMappingProps{
	Mapping: map[string]map[string]interface{}{
		"us-east-1": map[string]interface{}{
			"regionName": jsii.String("US East (N. Virginia)"),
		},
		"us-east-2": map[string]interface{}{
			"regionName": jsii.String("US East (Ohio)"),
		},
	},
})

regionTable.FindInMap(awscdk.Aws_REGION(), jsii.String("regionName"))

Initializer ​

ts
new CfnMapping(scope: Construct, id: string, props?: CfnMappingProps)
python
CfnMapping(scope: Construct, id: str, props: typing.Optional[CfnMappingProps] = None)
java
new CfnMapping(Construct scope, String id, CfnMappingProps props)
csharp
new CfnMapping(Construct scope, string id, CfnMappingProps? props = null)
go
NewCfnMapping(Scope Construct, Id *string, Props CfnMappingProps)

Construct Props ​

lazybooleanlazyboollazyBooleanLazyboolLazy*bool#
mapping{ [key: string]: { [key: string]: any } }mappingtyping.Mapping[str, typing.Mapping[str, Any]]mappingMap<String, Map<String, Object>>MappingIDictionary<string, IDictionary<string, object>>Mapping*map[string]*map[string]interface{}= No mapping.#
Mapping of key to a set of corresponding set of named values.
notes

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 ​

creationStackstring[]creation_stacktyping.List[str]creationStackList<String>CreationStackstring[]CreationStack*[]*stringrequired#
logicalIdstringlogical_idstrlogicalIdStringLogicalIdstringLogicalId*stringrequired#
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).

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
refstringrefstrrefStringRefstringRef*stringrequired#
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 }).

stackStackstackStackstackStackStackStackStackStackrequired#
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): stringdef find_in_map(self, key1: str, key2: str, default_value: typing.Optional[str] = None) -> strpublic String findInMap(String key1, String key2, String defaultValue)public string FindInMap(string key1, string key2, string? defaultValue = null)func FindInMap(Key1 *string, Key2 *string, DefaultValue *string) *string#
returns

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@staticmethod def is_cfn_element(x: Any) -> boolpublic static Boolean isCfnElement(Object x)public static bool IsCfnElement(object x)func IsCfnElement(X interface{}) *boolstatic#
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

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

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

overrideLogicalId(newLogicalId: string): voiddef override_logical_id(self, new_logical_id: str) -> Nonepublic void overrideLogicalId(String newLogicalId)public void OverrideLogicalId(string newLogicalId)func OverrideLogicalId(NewLogicalId *string)#
Overrides the auto-generated logical ID with a specific ID.
1 parameter

Parameters

  • newLogicalIdnew_logical_idnewLogicalIdnewLogicalIdNewLogicalId — The new logical ID to use for this stack element.
setValue(key1: string, key2: string, value: any): voiddef set_value(self, key1: str, key2: str, value: Any) -> Nonepublic void setValue(String key1, String key2, Object value)public void SetValue(string key1, string key2, object value)func SetValue(Key1 *string, Key2 *string, Value interface{})#
Sets a value in the map based on the two keys.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.