Using latest .NET CDK, I am trying to create a stack where Instance AMI is specified at deploy time depending on the region where stack is deployed. With regular CloudFormation I could do that using Mappings, AWS::Region and FindInMap function, but with CDK, GenericLinuxImage or LookupMachineImage appear to not accept Aws.REGION and the output of CfnMapping.FindInMap() - deferred values, and AMI and its region have to be known at synth time, which is not what I need.
When using GenericLinuxImage I get "Unable to determine AMI from AMI map since stack is region-agnostic" error.
Is it possible to use CfnMapping.FindInMap() and Aws.REGION to specify Instance custom AMI?
CFN snippet the behavior of which I want to reproduce:
Mappings:
RegionMap:
us-east-1:
AmiId: ami-XXXXXXXXXXX
...
Resources:
...
InstanceMachine:
Type: AWS::EC2::Instance
Properties:
InstanceType: t3a.large
ImageId: !FindInMap
- RegionMap
- !Ref 'AWS::Region'
- AmiId
Thanks, Vlad.