Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(core): fix CfnMapping example #16882

Merged
merged 7 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions packages/@aws-cdk/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,26 +753,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 @@ -787,24 +791,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
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