Skip to content

Commit b625510

Browse files
authored
docs(core): update old recommendations in core README (#28535)
`splitArn` is the correct updated version of `parseArn`. It's now necessary to use `ArnFormat` not a literal string for the format of the ARN resource for `splitArn` and `formatArn`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent dde5975 commit b625510

File tree

3 files changed

+191
-62
lines changed

3 files changed

+191
-62
lines changed

packages/aws-cdk-lib/README.md

+96-10
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ CloudFormation to re-read the secret.
396396
## ARN manipulation
397397

398398
Sometimes you will need to put together or pick apart Amazon Resource Names
399-
(ARNs). The functions `stack.formatArn()` and `stack.parseArn()` exist for
399+
(ARNs). The functions `stack.formatArn()` and `stack.splitArn()` exist for
400400
this purpose.
401401

402402
`formatArn()` can be used to build an ARN from components. It will automatically
@@ -409,12 +409,12 @@ declare const stack: Stack;
409409
stack.formatArn({
410410
service: 'lambda',
411411
resource: 'function',
412-
sep: ':',
412+
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
413413
resourceName: 'MyFunction'
414414
});
415415
```
416416

417-
`parseArn()` can be used to get a single component from an ARN. `parseArn()`
417+
`splitArn()` can be used to get a single component from an ARN. `splitArn()`
418418
will correctly deal with both literal ARNs and deploy-time values (tokens),
419419
but in case of a deploy-time value be aware that the result will be another
420420
deploy-time value which cannot be inspected in the CDK application.
@@ -423,14 +423,13 @@ deploy-time value which cannot be inspected in the CDK application.
423423
declare const stack: Stack;
424424

425425
// Extracts the function name out of an AWS Lambda Function ARN
426-
const arnComponents = stack.parseArn(arn, ':');
426+
const arnComponents = stack.splitArn(arn, ArnFormat.COLON_RESOURCE_NAME);
427427
const functionName = arnComponents.resourceName;
428428
```
429429

430-
Note that depending on the service, the resource separator can be either
431-
`:` or `/`, and the resource name can be either the 6th or 7th
432-
component in the ARN. When using these functions, you will need to know
433-
the format of the ARN you are dealing with.
430+
Note that the format of the resource separator depends on the service and
431+
may be any of the values supported by `ArnFormat`. When dealing with these
432+
functions, it is important to know the format of the ARN you are dealing with.
434433

435434
For an exhaustive list of ARN formats used in AWS, see [AWS ARNs and
436435
Namespaces](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)
@@ -611,7 +610,7 @@ response to the CloudFormation service and handle various error cases.
611610
Set `serviceToken` to `lambda.functionArn` to use this provider:
612611

613612
```ts
614-
const fn = new lambda.Function(this, 'MyProvider', functionProps);
613+
const fn = new lambda.SingletonFunction(this, 'MyProvider', functionProps);
615614

616615
new CustomResource(this, 'MyResource', {
617616
serviceToken: fn.functionArn,
@@ -625,7 +624,8 @@ framework designed to implement simple and slim custom resource providers. It
625624
currently only supports Node.js-based user handlers, represents permissions as raw
626625
JSON blobs instead of `iam.PolicyStatement` objects, and it does not have
627626
support for asynchronous waiting (handler cannot exceed the 15min lambda
628-
timeout).
627+
timeout). The `CustomResourceProviderRuntime` supports runtime `nodejs12.x`,
628+
`nodejs14.x`, `nodejs16.x`, `nodejs18.x`.
629629

630630
[`@aws-cdk/core.CustomResourceProvider`]: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.CustomResourceProvider.html
631631

@@ -1096,6 +1096,31 @@ declare const regionTable: CfnMapping;
10961096
regionTable.findInMap(Aws.REGION, 'regionName');
10971097
```
10981098

1099+
An optional default value can also be passed to `findInMap`. If either key is not found in the map and the mapping is lazy, `findInMap` will return the default value and not render the mapping.
1100+
If the mapping is not lazy or either key is an unresolved token, the call to `findInMap` will return a token that resolves to
1101+
`{ "Fn::FindInMap": [ "MapName", "TopLevelKey", "SecondLevelKey", { "DefaultValue": "DefaultValue" } ] }`, and the mapping will be rendered.
1102+
Note that the `AWS::LanguageExtentions` transform is added to enable the default value functionality.
1103+
1104+
For example, the following code will again not produce anything in the "Mappings" section. The
1105+
call to `findInMap` will be able to resolve the value during synthesis and simply return
1106+
`'Region not found'`.
1107+
1108+
```ts
1109+
const regionTable = new CfnMapping(this, 'RegionTable', {
1110+
mapping: {
1111+
'us-east-1': {
1112+
regionName: 'US East (N. Virginia)',
1113+
},
1114+
'us-east-2': {
1115+
regionName: 'US East (Ohio)',
1116+
},
1117+
},
1118+
lazy: true,
1119+
});
1120+
1121+
regionTable.findInMap('us-west-1', 'regionName', 'Region not found');
1122+
```
1123+
10991124
[cfn-mappings]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html
11001125

11011126
### Dynamic References
@@ -1187,6 +1212,13 @@ const stack = new Stack(app, 'StackName', {
11871212
});
11881213
```
11891214

1215+
You can also set termination protection with the setter after you've instantiated the stack.
1216+
1217+
```ts
1218+
const stack = new Stack(app, 'StackName', {});
1219+
stack.terminationProtection = true;
1220+
```
1221+
11901222
By default, termination protection is disabled.
11911223

11921224
### Description
@@ -1245,6 +1277,20 @@ It's possible to synthesize the project with more Resources than the allowed (or
12451277

12461278
Set the context key `@aws-cdk/core:stackResourceLimit` with the proper value, being 0 for disable the limit of resources.
12471279

1280+
### Template Indentation
1281+
1282+
The AWS CloudFormation templates generated by CDK include indentation by default.
1283+
Indentation makes the templates more readable, but also increases their size,
1284+
and CloudFormation templates cannot exceed 1MB.
1285+
1286+
It's possible to reduce the size of your templates by suppressing indentation.
1287+
1288+
To do this for all templates, set the context key `@aws-cdk/core:suppressTemplateIndentation` to `true`.
1289+
1290+
To do this for a specific stack, add a `suppressTemplateIndentation: true` property to the
1291+
stack's `StackProps` parameter. You can also set this property to `false` to override
1292+
the context key setting.
1293+
12481294
## App Context
12491295

12501296
[Context values](https://docs.aws.amazon.com/cdk/v2/guide/context.html) are key-value pairs that can be associated with an app, stack, or construct.
@@ -1440,6 +1486,10 @@ class MyPlugin implements IPolicyValidationPluginBeta1 {
14401486
}
14411487
```
14421488

1489+
In addition to the name, plugins may optionally report their version (`version`
1490+
property ) and a list of IDs of the rules they are going to evaluate (`ruleIds`
1491+
property).
1492+
14431493
Note that plugins are not allowed to modify anything in the cloud assembly. Any
14441494
attempt to do so will result in synthesis failure.
14451495

@@ -1452,4 +1502,40 @@ add it to the `postinstall`
14521502
[script](https://docs.npmjs.com/cli/v9/using-npm/scripts) in the `package.json`
14531503
file.
14541504

1505+
## Annotations
1506+
1507+
Construct authors can add annotations to constructs to report at three different
1508+
levels: `ERROR`, `WARN`, `INFO`.
1509+
1510+
Typically warnings are added for things that are important for the user to be
1511+
aware of, but will not cause deployment errors in all cases. Some common
1512+
scenarios are (non-exhaustive list):
1513+
1514+
- Warn when the user needs to take a manual action, e.g. IAM policy should be
1515+
added to an referenced resource.
1516+
- Warn if the user configuration might not follow best practices (but is still
1517+
valid)
1518+
- Warn if the user is using a deprecated API
1519+
1520+
### Acknowledging Warnings
1521+
1522+
If you would like to run with `--strict` mode enabled (warnings will throw
1523+
errors) it is possible to `acknowledge` warnings to make the warning go away.
1524+
1525+
For example, if > 10 IAM managed policies are added to an IAM Group, a warning
1526+
will be created:
1527+
1528+
```text
1529+
IAM:Group:MaxPoliciesExceeded: You added 11 to IAM Group my-group. The maximum number of managed policies attached to an IAM group is 10.
1530+
```
1531+
1532+
If you have requested a [quota increase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html#reference_iam-quotas-entities)
1533+
you may have the ability to add > 10 managed policies which means that this
1534+
warning does not apply to you. You can acknowledge this by `acknowledging` the
1535+
warning by the `id`.
1536+
1537+
```ts
1538+
Annotations.of(this).acknowledgeWarning('IAM:Group:MaxPoliciesExceeded', 'Account has quota increased to 20');
1539+
```
1540+
14551541
<!--END CORE DOCUMENTATION-->

0 commit comments

Comments
 (0)