Skip to content
Closed
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
7 changes: 4 additions & 3 deletions packages/aws-cdk-lib/aws-s3-deployment/lib/render-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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] };
18 changes: 17 additions & 1 deletion packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
});
Loading