Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"Conditions": {
"MyCondition": {
"Fn::Equals": [
"true",
"true"
]
}
},
"Resources": {
"MyFunctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
}
}
},
"MyFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": ""
},
"Handler": "lambda_function.lambda_handler",
"Layers": {
"Fn::If": [
"MyCondition",
[],
[
"arn:aws:lambda:us-east-1:123456789012:layer:example-layer:1"
]
]
},
"Role": {
"Fn::GetAtt": [
"MyFunctionRole",
"Arn"
]
},
"Runtime": "python3.12"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ describe('CDK Include', () => {
);
});

test('can ingest a template with Lambda Layers defined with Fn::If condition', () => {
includeTestTemplate(stack, 'lambda-layers-with-condition.json');

Template.fromStack(stack).templateMatches(
loadTestFileToJsObject('lambda-layers-with-condition.json'),
);
});

test('can ingest a template with fn:: intrinsic function used in deletion policy', () => {
includeTestTemplate(stack, 'intrinsic-deletion-policy.json');

Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/spec2cdk/lib/cdk/resolver-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class ResolverBuilder {
const resolver = (_: Expression) => {
if (resolvableType.arrayOfType) {
return expr.directCode(
`(props.${name}?.forEach((item: ${propType.arrayOfType!.toString()}, i: number, arr: ${propType.toString()}) => { arr[i] = ${buildChain('item')}; }), props.${name} as ${resolvableType.toString()})`,
`(cdk.withResolved(props.${name}, () => props.${name}?.forEach((item: ${propType.arrayOfType!.toString()}, i: number, arr: ${propType.toString()}) => { arr[i] = ${buildChain('item')}; })), props.${name} as ${resolvableType.toString()})`,
);
} else {
return expr.directCode(buildChain(`props.${name}`));
Expand Down
Loading