Commit 79d91ad
authored
fix(elasticache): security group for
### Issue # (if applicable)
N/A
### Reason for this change
A security group ingress for the new `ServerlessCache` construct does not use an endpoint port.
The following CDK code generates an INVALID CFn template with `null` for `FromPort` and `ToPort`:
```ts
const cache = new ServerlessCache(this, 'ServerlessCache', {
vpc,
});
const sg = new SecurityGroup(this, 'SecurityGroup', {
vpc,
});
sg.connections.allowToDefaultPort(cache);
```
```json
"SecurityGroupfromawscdkserverlesscacheClientSG6D18D5F9IndirectPortFE633A67": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
// ...
// ...
"FromPort": null,
// ...
// ...
"ToPort": null
},
```
An expected template:
```json
"SecurityGroupfromawscdkserverlesscacheClientSG6D18D5F9IndirectPortFE633A67": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
// ...
// ...
"FromPort": {
"Fn::GetAtt": [
"Cache18F6EE16",
"Endpoint.Port"
]
},
// ...
// ...
"ToPort": {
"Fn::GetAtt": [
"Cache18F6EE16",
"Endpoint.Port"
]
}
}
},
```
FYI: The method `cache.connections.defaultPort?.toRuleJson()` outputs `{"Value":{"ipProtocol":"tcp","fromPort":null,"toPort":null}}`. But we expect `{"Value":{"ipProtocol":"tcp","fromPort":{"Fn::GetAtt":["Cache18F6EE16","Endpoint.Port"]},"toPort":{"Fn::GetAtt":["Cache18F6EE16","Endpoint.Port"]}}}`.
### Description of changes
Use `Token.asNumber` for the `defaultPort` of `Connections` in `ServerlessCache`:
```diff
this.connections = new ec2.Connections({
securityGroups: this.securityGroups,
- defaultPort: ec2.Port.tcp(Lazy.number({ produce: () => parseInt(this.serverlessCacheEndpointPort) })),
+ defaultPort: ec2.Port.tcp(Token.asNumber(this.serverlessCacheEndpointPort)),
});
```
### Describe any new or updated permissions being added
### Description of how you validated changes
Both an unit test and an integ test.
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*ServerlessCache does not use default endpoint port (#35738)1 parent 40a7689 commit 79d91ad
10 files changed
Lines changed: 331 additions & 32 deletions
File tree
- packages/@aws-cdk/aws-elasticache-alpha
- lib
- test
- integ.serverless-cache.js.snapshot
- asset.c11608a15785084ea1afe65826e575ee316add10c8b1bb373e93297e26aec564.bundle
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
472 | | - | |
| 472 | + | |
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| |||
Lines changed: 26 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
549 | 580 | | |
550 | 581 | | |
551 | 582 | | |
| |||
622 | 653 | | |
623 | 654 | | |
624 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
625 | 672 | | |
626 | 673 | | |
627 | 674 | | |
| |||
Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments