Skip to content

Commit

Permalink
apply sames changes to aws-cdk-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jumic committed Oct 11, 2021
1 parent 04b476b commit 7a1eab1
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/aws-cdk-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -786,26 +786,30 @@ CloudFormation [mappings][cfn-mappings] are created and queried using the
```ts
const regionTable = new CfnMapping(this, 'RegionTable', {
mapping: {
regionName: {
'us-east-1': 'US East (N. Virginia)',
'us-east-2': 'US East (Ohio)',
'us-east-1': {
regionName: 'US East (N. Virginia)',
// ...
},
'us-east-2': {
regionName: 'US East (Ohio)',
// ...
},
// ...
}
});

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

This will yield the following template:

```yaml
Mappings:
RegionTable:
regionName:
us-east-1: US East (N. Virginia)
us-east-2: US East (Ohio)
us-east-1:
regionName: US East (N. Virginia)
us-east-2:
regionName: US East (Ohio)
```
Mappings can also be synthesized "lazily"; lazy mappings will only render a "Mappings"
Expand All @@ -820,24 +824,25 @@ call to `findInMap` will be able to resolve the value during synthesis and simpl
```ts
const regionTable = new CfnMapping(this, 'RegionTable', {
mapping: {
regionName: {
'us-east-1': 'US East (N. Virginia)',
'us-east-2': 'US East (Ohio)',
'us-east-1': {
regionName: 'US East (N. Virginia)',
},
'us-east-2': {
regionName: 'US East (Ohio)',
},
},
lazy: true,
});
regionTable.findInMap('regionName', 'us-east-2');
regionTable.findInMap('us-east-2', 'regionName');
```

On the other hand, the following code will produce the "Mappings" section shown above,
since the second-level key is an unresolved token. The call to `findInMap` will return a
token that resolves to `{ Fn::FindInMap: [ 'RegionTable', 'regionName', { Ref: AWS::Region
} ] }`.
since the top-level key is an unresolved token. The call to `findInMap` will return a token that resolves to
`{ "Fn::FindInMap": [ "RegionTable", { "Ref": "AWS::Region" }, "regionName" ] }`.

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

[cfn-mappings]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html
Expand Down

0 comments on commit 7a1eab1

Please sign in to comment.