I understand that context is what ever name you define in your Lambda functions but when it comes to Appsync resolvers I'm a bit confused. I've seen both $ctx
and $context
being used in AppSync resolvers including in AWS docs. Some of AWS's own code generation tools like AWS Amplify CLI create resolvers that use both in the same code! I can't find anything in the docs explaining this. What's going on here?
Asked
Active
Viewed 3,808 times
14

user3376065
- 1,137
- 1
- 13
- 31
-
1I'm in the process of scrubbing our docs and replacing `$context` with `$ctx` for consistency. I'll add a note to the [Resolver Mapping page](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html) explaining that `$ctx` is an alias. Sorry for the confusion. – Rohan Deshpande Mar 19 '19 at 15:53
1 Answers
27
(AWS AppSync dev here)
$ctx
and $context
in AWS AppSync refer to the same Resolver Context. We added $ctx
as an alias for $context
to reduce the number of characters users have to type ($ctx
is 50% shorter than $context
!!)
Choosing $context
or $ctx
is a personal preference. I prefer $ctx
when I'm authoring AWS AppSync resolvers.

Rohan Deshpande
- 3,535
- 1
- 26
- 31
-
1thank you for the answer. Does the same apply to arguments? I've seen some place use $ctx.args... ?Any other helpful aliases? – user3376065 Mar 19 '19 at 20:48
-
-
Just a minor note, $ctx is not allowed when referencing cache keys. Caching keys need to start with $context.args, $context.arguments, $context.identity, or $context.source, otherwise AppSync fails with 400 – tratto Jul 02 '21 at 15:58
-
3