From de20bbe0ed9d017aed649e94a9af602e308e0aea Mon Sep 17 00:00:00 2001 From: arvchahal Date: Tue, 18 Mar 2025 16:08:53 -0500 Subject: [PATCH] n --- .../aws-s3-deployment/lib/render-data.ts | 7 ++++--- .../aws-s3-deployment/test/content.test.ts | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts b/packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts index 7d9979a9f4cf5..6f814017c49bf 100644 --- a/packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts +++ b/packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts @@ -58,9 +58,9 @@ export function renderData(scope: Construct, data: string): Content { throw new ValidationError('Unexpected: Expecting `resolve()` to return "Fn::Join", "Ref" or "Fn::GetAtt"', scope); } - function addMarker(part: Ref | GetAtt | FnSelect) { + function addMarker(part: Ref | GetAtt | FnSelect |FnFindInMap) { const keys = Object.keys(part); - const acceptedCfnFns = ['Ref', 'Fn::GetAtt', 'Fn::Select']; + const acceptedCfnFns = ['Ref', 'Fn::GetAtt', 'Fn::Select','Fn::FindInMap']; if (keys.length !== 1 || !acceptedCfnFns.includes(keys[0])) { const stringifiedAcceptedCfnFns = acceptedCfnFns.map((fn) => `"${fn}"`).join(' or '); throw new ValidationError(`Invalid CloudFormation reference. Key must start with any of ${stringifiedAcceptedCfnFns}. Got ${JSON.stringify(part)}`, scope); @@ -75,8 +75,9 @@ export function renderData(scope: Construct, data: string): Content { } type FnJoin = [string, FnJoinPart[]]; -type FnJoinPart = string | Ref | GetAtt | FnSelect; +type FnJoinPart = string | Ref | GetAtt | FnSelect | FnFindInMap; type Ref = { Ref: string }; type GetAtt = { 'Fn::GetAtt': [string, string] }; type FnSplit = { 'Fn::Split': [string, string | Ref] }; type FnSelect = { 'Fn::Select': [number, string[] | FnSplit] }; +type FnFindInMap = { 'Fn::FindInMap': [string, string, string] }; diff --git a/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts b/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts index 2f1c6d1ddf542..27d0d3e3a559c 100644 --- a/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts +++ b/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts @@ -2,7 +2,8 @@ import { Vpc } from '../../aws-ec2'; import * as elbv2 from '../../aws-elasticloadbalancingv2'; import * as lambda from '../../aws-lambda'; import * as s3 from '../../aws-s3'; -import { Lazy, Stack } from '../../core'; +import * as iam from '../../aws-iam'; +import { Lazy, Stack ,Fn, CfnMapping} from '../../core'; import { Source } from '../lib'; import { renderData } from '../lib/render-data'; @@ -154,3 +155,18 @@ test('lazy string which resolves to something with a deploy-time value', () => { markers: { }, }); }); + +test('supports Fn::FindInMap in deploy-time json data', () => { + const stack = new Stack(); + const mapping = new CfnMapping(stack, 'TestMapping', { + mapping: { responseTemplate: { full: 'example value' } }, + }); + + const source = Source.jsonData('file.json', { + key: Fn.findInMap('TestMapping', 'responseTemplate', 'full'), + }); + + expect(() => source.bind(stack, { handlerRole: new iam.Role(stack, 'Role', { + assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), + }) })).not.toThrow(); +});