AWS exposes region long names (like Asia Pacific (Singapore)
for ap-southeast-1
) as publicly available Parameter Store parameters. Lookup this value at synth-time with ssm.StringParameter.valueFromLookup*. You need the region id for the parameter path, which a stack (or construct) can introspect.
export class MyStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
const regionLongName: string = ssm.StringParameter.valueFromLookup(
this,
`/aws/service/global-infrastructure/regions/${this.region}/longName`
);
console.dir({ region: this.region, regionLongName });
}
}
For Python
aws_cdk.aws_ssm.StringParameter.value_from_lookup(
scope=self,
parameter_name=f'/aws/service/global-infrastructure/regions/{self.region}/longName')
cdk synth
output::
{ region: 'us-east-1', regionLongName: 'US East (N. Virginia)' }
* The CDK's valueFromLookup
context method will cache the looked-up parameter store value in cdk.context.json
at synth-time. You may initially get a dummy value. Just synth again.