apigateway: Unable to serialize value as aws-cdk-lib.aws_apigateway.IModel with Model.EMPTY_MODEL

Using the CDK in Python with awsapigateway, referencing agw.Model.EMPTYMODEL in method responses started failing with jsii.errors.JavaScriptError: Unable to serialize value as aws-cdk-lib.awsapigateway.IModel. It affected CDK users in every language except TypeScript/JavaScript, on framework versions 2.41.0 through 2.43.0. The cause was that EMPTYMODEL returned an instance of a deprecated class that jsii could not serialize across languages.

This was a framework bug in aws-cdk-lib 2.41.0 to 2.43.0, fixed upstream, so upgrade to a version newer than 2.43.0. The issue only hit non-TypeScript languages using Model.EMPTYMODEL (or other values returning deprecated class instances). After upgrading, the same MethodResponse code with responsemodels={'application/json': agw.Model.EMPTY_MODEL} synthesizes normally again. Source: https://github.com/aws/aws-cdk/issues/21902