fix(cli): clear error for intrinsic certificateArn in domain commands#718
fix(cli): clear error for intrinsic certificateArn in domain commands#718sid88in wants to merge 1 commit into
Conversation
The `appsync domain` CLI commands call the AppSync SDK directly, which needs a literal certificate ARN string. Passing a CloudFormation intrinsic (e.g. Fn::ImportValue) — valid in the CloudFormation path — previously failed with the cryptic SDK error 'Expected params.certificateArn to be a string'. Throw an actionable error from createDomain() when certificateArn is not a string, pointing users to either a literal ARN or the CloudFormation integration (where the intrinsic resolves). Widen DomainConfig. certificateArn to string | IntrinsicFunction to match validation, add a negative test, and note the limitation in the custom-domain docs. Closes #532
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR adds runtime validation to enforce that when using the CLI to manage custom domains, the ChangesCLI Domain ARN Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
What
Give a clear, actionable error when a CloudFormation intrinsic function (e.g.
Fn::ImportValue) is passed asdomain.certificateArnto theappsync domainCLI commands, instead of the cryptic SDK errorExpected params.certificateArn to be a string.Closes #532.
Why
domain.certificateArnis validated asstringOrIntrinsicFunction, which accepts any object — intentionally, because in the CloudFormation path the value is written straight into theAWS::AppSync::DomainNameresource, where an intrinsic likeFn::ImportValueis valid and gets resolved at deploy time.The CLI path is different.
createDomain()calls the AppSync SDK'sCreateDomainNameCommanddirectly, which needs a resolved string ARN. There is no CloudFormation context to resolve an intrinsic client‑side, so passing one currently fails deep in the SDK withExpected params.certificateArn to be a string— which gives the user no hint about the actual problem (as reported in #532).This is the CloudFormation‑passthrough vs. CLI/synth‑time distinction: an intrinsic
certificateArnis meaningful only for values written through to the template, not for a value the CLI must hand to the SDK.The fix
createDomain()(src/index.ts): after resolvingcertificateArn, throw a plugin error if it is not a string, explaining that the CLI requires a literal ARN and that intrinsic functions are only resolved via the CloudFormation integration (the defaultdomain.useCloudFormation: true). The check sits before the SDK call, so we fail fast with guidance instead of a SDK type error.DomainConfig.certificateArntype (src/types/common.ts): widened fromstringtostring | IntrinsicFunctionto match what validation actually accepts. This also makes the runtime guard type‑meaningful (it narrows the union) and matches the convention used for other intrinsic‑capable fields in the codebase. (IntrinsicFunctionis already imported in this file.)doc/custom-domain.md): a note in the "Using CloudFormation vs the CLI commands" section that the CLI requires a literal ARN and that intrinsic functions are only resolved when the domain is managed by CloudFormation.What this does NOT change (intentional)
certificateArn— that is correct for the CloudFormation path and must not be tightened.AWS::AppSync::DomainNameCertificateArnproperty and is resolved by CloudFormation. So the real answer to "how do I use an imported cert ARN?" — use the CloudFormation integration — keeps working; this PR just makes the CLI fail clearly instead of cryptically.IntrinsicFunctionis not broadened to addFn::ImportValue(it currently modelsFn::GetAtt/Fn::Join/Ref/Fn::Sub). That's a pre‑existing, separate limitation; validation already accepts any object at runtime, and the new guard catches every non‑string regardless of the exact union, so the fix is correct without touching the shared type.Testing
appsync domain createwithcertificateArn: { 'Fn::ImportValue': ... }anduseCloudFormation: falserejects with the new message, andCreateDomainNameCommandis never sent.npm run build,npm run lint(0 errors),npm test(332 passing),npm run test:e2e(84 passing), andprettier --check doc/custom-domain.mdall pass.Confidence
createDomain→ SDK vscompileCustomDomain→ template) and the validation schema.Summary by CodeRabbit
Documentation
Bug Fixes
Tests