aws / aws/aws-appsync-community
Per Resolver CachingKeys for Cognito Custom Attribute
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
My Cognito schema has a custom attribute tenantId
I am able to access this attribute in VTL using #set( $tenantId = $ctx.identity.claims.get(\"custom:tenantId\") )
I have cache specified via CDK as
const apiCache = new appsync.CfnApiCache(this, 'APICache', {
apiId: apiId.stringValue,
apiCachingBehavior: 'PER_RESOLVER_CACHING',
type: 'SMALL',
ttl: 300
});
Resolver as
const listBrandsResolver = new appsync.CfnResolver(this, 'ListBrandsResolver', {
apiId: serviceApiId.stringValue,
dataSourceName: serviceDsName.stringValue,
typeName: 'Query',
fieldName: 'listBrands',
cachingConfig: {
ttl: 3600,
cachingKeys: [
'$context.identity.claims.tenantId'
]
},
requestMappingTemplateS3Location: `s3://${resolverBucket}/${resolverPath}/Query.listBrands.request.vtl`,
responseMappingTemplateS3Location: `s3://${resolverBucket}/${resolverPath}/Query.listItems.response.vtl`
});
I have tried all manner of variants of the cachingKeys array to no success.
I keep getting an error with "UPDATE_FAILED | AWS::AppSync::Resolver | ListBrandsResolver Caching keys need to start with $context.args, $context.arguments, $context.identity, or $context.source. (Service: AWSAppSync; Status Code: 400; Error Code: BadRequestException; Request ID: 8e6eb413-bdb5-46d7-a21f-b85eb93f52d6; Proxy: null)"
I can't find any documentation for guidance, only references to 'direct attributes'
The AppSync Console is no use either as when trying to enable caching on a resolver, only get to set the TTL via the Console UI
Contributor guide
Research direction
Start with the AWS AppSync CfnResolver cachingConfig.cachingKeys entry and the reported deployment error; the issue also shows the Cognito claim access in the VTL mapping template. Check the accepted $context.identity path for a custom Cognito attribute and confirm the resolver deploys with tenant-specific caching; document the working syntax and any console limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, graphql
- Domain
- api, cloud, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100