-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When the regex alternation tries to match scalar AWSDateTime, it matches scalar AWSDate first (because AWSDate appears before AWSDateTime in the list), removes it, and leaves Time behind causing the syntax error and AppSync deployment to fail.
Expected Behavior
The schema should parse correctly.
How are you starting LocalStack?
With the localstack script
Steps To Reproduce
How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)
localstack start
Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)
cdklocal deploy --all
Environment
- OS: MacOS 26.1
- LocalStack: Pro
LocalStack version: 4.10.1.dev41
LocalStack Docker image sha: f71fee9f3a3f
LocalStack build date: 2025-11-19
LocalStack build git hash: 252071cd1Anything else?
Summary
LocalStack's AppSync provider fails to parse GraphQL schemas containing scalar AWSDateTime with the error:
Syntax Error: Unexpected Name 'Time'.
GraphQL request:38:1
39 | TimeFull Disclosure
I performed an exec into the localstack-main container and figured out how to decrypt the Python files so I could debug this and discover the root cause.
Root Cause
In localstack/pro/core/services/appsync/graphql_executor.py, line 136, the regex used to remove AWS scalar type definitions has a bug:
AWS_SCALAR_TYPES=['AWSDate','AWSTime','AWSDateTime','AWSTimestamp','AWSEmail','AWSJSON','AWSURL','AWSPhone','AWSIPAddress']
AWS_SCALAR_REGEX=f"scalar\\s+(?:{"|".join(AWS_SCALAR_TYPES)})"
# Line 136:
A=re.sub(AWS_SCALAR_REGEX,'',A)The Problem: When the regex alternation tries to match scalar AWSDateTime, it matches scalar AWSDate first (because AWSDate appears before AWSDateTime in the list), removes it, and leaves Time behind.
Example
Input schema:
scalar AWSDateTimeAfter regex substitution:
TimeThis causes GraphQL to fail parsing with "Unexpected Name 'Time'".
Fix Options
Option 1: Sort by length (longest first)
AWS_SCALAR_REGEX = r"scalar\s+(?:" + "|".join(sorted(AWS_SCALAR_TYPES, key=len, reverse=True)) + ")"Option 2: Add word boundary
AWS_SCALAR_REGEX = r"scalar\s+(?:" + "|".join(AWS_SCALAR_TYPES) + r")\b"Both fixes ensure that longer type names like AWSDateTime are matched completely before shorter ones like AWSDate.
Reproduction
- Create a GraphQL schema with
scalar AWSDateTime - Deploy to LocalStack using CDK or CloudFormation
- Observe the error:
Syntax Error: Unexpected Name 'Time'
Verification
import re
AWS_SCALAR_TYPES=['AWSDate','AWSTime','AWSDateTime','AWSTimestamp','AWSEmail','AWSJSON','AWSURL','AWSPhone','AWSIPAddress']
# Buggy regex
AWS_SCALAR_REGEX_BUGGY = r"scalar\s+(?:" + "|".join(AWS_SCALAR_TYPES) + ")"
test = "scalar AWSDateTime"
print(re.sub(AWS_SCALAR_REGEX_BUGGY, '', test)) # Output: "Time"
# Fixed regex (with word boundary)
AWS_SCALAR_REGEX_FIXED = r"scalar\s+(?:" + "|".join(AWS_SCALAR_TYPES) + r")\b"
print(re.sub(AWS_SCALAR_REGEX_FIXED, '', test)) # Output: ""