AppSync: how to implement unauthenticated operations


AppSync doesn’t allow unauthenticated API calls. To allow users to call your API without first authenticating themselves, you must mimic the behaviour using one of the available authorization methods [1].

In this post, let’s look at three ways to implement unauthenticated GraphQL operations with AppSync and their pros & cons.

API Keys

To use API keys, you need to:

  1. Add an API Key in AppSync.
  2. Pass the API Key in the x-api-key header.

That’s it! It’s the easiest and most common way to implement unauthenticated GraphQL operations in AppSync.

However, AppSync API keys has a max expiry of 365 days. You can extend this by a further 365 days with the UpdateApiKey API [2]. There is no limit to how many times you can extend an API key’s expiry date.

In practice, it means you need a cron job to keep extending your API key’s expiry. It’s a manageable nuisance.

Finally, there’s no extra charge for using API keys.

Lambda authorizer

With a Lambda authorizer, the caller must provide a non-empty string in the authorization header. Instead of API keys, you can pass along a shared secret in the authorization header.

This gives you more control over the lifecycle of the shared secret (compared to using API keys).

You can also support multiple shared secrets with different levels of access. For example, different shared secrets for different clients, like this:

This is easy to implement, and you can cache authorization results for up to an hour. Furthermore, you can eliminate invalid authorization headers using the IdentityValidationExpression.

It’s a regex that allows AppSync to reject invalid authorization tokens without needing to invoke your Lambda authorizer. Of course, you won’t pay for these unauthorized requests.

However, even with caching, there will still be additional charges involved for the Lambda authorizer. There is also a performance hit because of Lambda cold starts, especially if caching means the function will not be invoked frequently.

AWS IAM

Lastly, you can use Cognito Identity Pool to issue temporary IAM credentials for unauthenticated clients. The client can then use these temporary IAM credentials to call AppSync.

Cognito Identity Pool is free to use, but the GetCredentialsForIdentity API call has a default throughput limit of 200 reqs/s.

Luckily, this is a soft limit and can be raised through the Service Quotas console or a support ticket.

Conclusions

You can enable unauthenticated GraphQL operations in AppSync through three main approaches.

  1. API Keys:east to set up and free to use, but requires periodic key renewal and offers limited control over individual clients.
  2. Lambda Authorizer (with shared secrets): offers more fine-grained access control at the expense of extra Lambda costs and potential latency from cold starts.
  3. AWS IAM via Cognito Identity Pool: leverages temporary AWS credentials for fine-grained access control. Free to use, (can be) highly scalability, though initial throughput limits and setup complexity may be a hurdle for simple use cases.

Here is a side-by-side comparison of their pros and cons:

Links

[1] Configuring authorization and authentication to secure your GraphQL APIs

[2] UpdateApiKey API

Master Serverless

Join 17K readers and level up you AWS game with just 5 mins a week.

Read more from Master Serverless

Modern applications rarely do just one thing at a time. An API request creates an order, and then another service needs to reserve stock, another to charge the customer, another to send an email, and so on. In a serverless or event-driven architecture, follow-up actions are usually triggered by messages (either events or commands). That gives us loose coupling, better scalability, and independent services. But it also introduces a reliability problem. “What happens when the database update...

If you use Claude Code a lot, you’ve probably run into usage limits, sometimes even in short coding sessions. But cost isn’t the only problem. In long-running sessions, the context window eventually fills up, and that can cause the agent to forget earlier decisions, lose important details, or come back from compaction with gaps in its working memory. Here are three tools worth checking out if you want to reduce token usage and make longer coding sessions possible. 1. CavemanThis is a Claude...

AI agents can now scan an entire open-source codebase for exploitable vulnerabilities in hours. Frontier models carry the complete library of known bug classes in their weights. So you can simply point an AI agent at a codebase and tell it to find zero-days. This isn't theoretical. Willy Tarreau, the HAProxy lead developer, reports that security bug reports have jumped from 2–3 per week to 5–10 per day. Greg Kroah-Hartman, the Linux kernel maintainer, described what happened: "Months ago, we...