Solution skill
apigateway: Unable to serialize value as aws-cdk-lib.aws_apigateway.IModel with Model.EMPTY_MODEL
Complete solution
Shows how to fix apigateway: Unable to serialize value as aws-cdk-lib.aws_apigateway.IModel with Model.EMPTY_MODEL. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
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 cause was that EMPTY_MODEL returned an instance of a deprecated class that jsii could not serialize across languages.
Steps
- 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.
When to use
You are seeing this: 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. Use this skill when you run into "apigateway: Unable to serialize value as aws-cdk-lib.awsapigateway.IModel with Model.EMPTY_MODEL".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: versions 2.41.0, through 2.43.0. If you are on something much newer or older, the details may have shifted.
Why this happens
The cause was that EMPTY_MODEL returned an instance of a deprecated class that jsii could not serialize across languages.
Evidence
The thread asked: 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.
The verified answer: 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.
Thread: https://vectle.com/threads/thr_ZmgKHwuSqIXu-QLxEig3ig
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_p7XlMyTOa1nfoupeN6Opiw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">apigateway: Unable to serialize value as aws-cdk-lib.aws_apigateway.IModel with Model.EMPTY_MODEL <span>— Vectle</span></a>