aws-s3-deployment: Support `CfnMapping` (Fn::FindInMap) in deploy time values for `Source.jsonData`
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
As discussed in https://github.com/aws/aws-cdk/issues/25504 and addressed partially in https://github.com/aws/aws-cdk/pull/27237, support for `Fn::FindInMap` in deploy time values for `Source.jsonData` is still needed.
Currently, using `Fn::FindInMap` results in the following error:
```
api-infra: Error: Invalid CloudFormation reference. Key must start with any of "Ref" or "Fn::GetAtt" or "Fn::Select". Got {"Fn::FindInMap":["DefaultMapping","responseTemplate","full"]}
api-infra: at addMarker (/Users/vale/Workspace/api/node_modules/.pnpm/aws-cdk-lib@2.143.0_constructs@10.3.0/node_modules/aws-cdk-lib/aws-s3-deployment/lib/render-data.js:1:1336)
api-infra: at renderData (/Users/vale/Workspace/api/node_modules/.pnpm/aws-cdk-lib@2.143.0_constructs@10.3.0/node_modules/aws-cdk-lib/aws-s3-deployment/lib/render-data.js:1:799)
api-infra: at Object.bind (/Users/vale/Workspace/api/node_modules/.pnpm/aws-cdk-lib@2.143.0_constructs@10.3.0/node_modules/aws-cdk-lib/aws-s3-deployment/lib/source.js:1:1919)
api-infra: at Object.bind (/Users/vale/Workspace/api/node_modules/.pnpm/aws-cdk-lib@2.143.0_constructs@10.3.0/node_modules/aws-cdk-lib/aws-s3-deployment/lib/source.js:1:2306)
api-infra: at /Users/vale/Workspace/api/node_modules/.pnpm/aws-cdk-lib@2.143.0_constructs@10.3.0/node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:3768
api-infra: at Array.map ()
api-infra: at new BucketDeployment (/Users/vale/Workspace/api/node_modules/.pnpm/aws-cdk-lib@2.143.0_constructs@10.3.0/node_modules/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.js:1:3749)
api-infra: at new TypeSafeRestApi (/Users/vale/Workspace/api/node_modules/.pnpm/file+..+..+..+lab+aws-pdk+packages+pdk+dist+js+package_@aws-cdk+aws-cognito-identitypool-alph_2yxqjbpf3vtng3yuse5lau2hn4/node_modules/@aws/pdk/type-safe-api/construct/type-safe-rest-api.ts:176:5)
api-infra: at new Api (/Users/vale/Workspace/api/packages/api/generated/infrastructure/typescript/src/api.ts:18:5)
api-infra: at new Api (/Users/vale/Workspace/api/packages/api/infra/src/constructs/apis/api.ts:468:5)
```
### Use Case
In large APIs with custom response templates, such as code error mappings, it's necessary to use `CfnMapping` to avoid CloudFormation template size limits. Repeating the same mapping multiple times causes CloudFormation to raise an error due to template size constraints. By using `CfnMapping`, we can maintain a single instance of the mapping, reducing the overall template size.
This is discussed here https://github.com/aws/aws-pdk/issues/771
### Proposed Solution
Extend the functionality introduced in https://github.com/aws/aws-cdk/pull/27237 to support `Fn::FindInMap` in deploy time values for `Source.jsonData`.
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.143.0
### Environment details (OS name and version, etc.)
macOS Sonoma 14.5 Apple M1 Pro
Contributor guide
Research direction
Start in aws-s3-deployment's render-data.js and source.js, using the failure path and PR #27237 as entry points; inspect how Source.jsonData deploy-time values are rendered and how CloudFormation intrinsic references are validated. Done means Fn::FindInMap is accepted for this value without the reported invalid-reference error, with coverage for the requested case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100