Crate lambda_appsync

Source
Expand description

This crate provides procedural macros and types for implementing AWS AppSync Direct Lambda resolvers.

It helps convert GraphQL schemas into type-safe Rust code with full AWS Lambda runtime support. The main functionality is provided through the appsync_lambda_main and appsync_operation macros.

§Complete Example

use lambda_appsync::{appsync_lambda_main, appsync_operation, AppsyncError};

// 1. First define your GraphQL schema (e.g. `schema.graphql`):
//
// type Query {
//   players: [Player!]!
//   gameStatus: GameStatus!
// }
//
// type Player {
//   id: ID!
//   name: String!
//   team: Team!
// }
//
// enum Team {
//   RUST
//   PYTHON
//   JS
// }
//
// enum GameStatus {
//   STARTED
//   STOPPED
// }

// 2. Initialize the Lambda runtime with AWS SDK clients in main.rs:

// Optional hook for custom request validation/auth
async fn verify_request(
    event: &lambda_appsync::AppsyncEvent<Operation>
) -> Option<lambda_appsync::AppsyncResponse> {
    // Return Some(response) to short-circuit normal execution
    None
}
// Generate types and runtime setup from schema
appsync_lambda_main!(
    "schema.graphql",
    // Initialize DynamoDB client if needed
    dynamodb() -> aws_sdk_dynamodb::Client,
    // Enable validation hook
    hook = verify_request,
    // Enable batch processing
    batch = true
);

// 3. Implement resolver functions for GraphQL operations:

#[appsync_operation(query(players))]
async fn get_players() -> Result<Vec<Player>, AppsyncError> {
    let client = dynamodb();
    todo!()
}

#[appsync_operation(query(gameStatus))]
async fn get_game_status() -> Result<GameStatus, AppsyncError> {
    let client = dynamodb();
    todo!()
}
// The macro ensures the function signature matches the GraphQL schema
// and wires everything up to handle AWS AppSync requests automatically

Re-exports§

pub use aws_config;
pub use env_logger;
pub use lambda_runtime;
pub use log;
pub use serde;
pub use serde_json;
pub use tokio;

Modules§

subscription_filters
GraphQL subscription filter implementation for AWS AppSync

Macros§

appsync_lambda_main
Generates the code required to handle AWS AppSync Direct Lambda resolver events based on a GraphQL schema.

Structs§

AWSDate
AWS AppSync specific GraphQL scalar type implemented a String new-type
AWSDateTime
AWS AppSync specific GraphQL scalar type implemented a String new-type
AWSEmail
AWS AppSync specific GraphQL scalar type implemented a String new-type
AWSPhone
AWS AppSync specific GraphQL scalar type implemented a String new-type
AWSTime
AWS AppSync specific GraphQL scalar type implemented a String new-type
AWSTimestamp
AWS AppSync specific GraphQL scalar type implemented SystemTime new-type. Note that this type implements Copy
AWSUrl
AWS AppSync specific GraphQL scalar type implemented a String new-type
AppsyncError
Error type for AWS AppSync operations
AppsyncEvent
Represents a complete AWS AppSync event sent to a Lambda resolver.
AppsyncEventInfo
Metadata about an AppSync GraphQL operation execution.
AppsyncIdentityCognito
Identity information for Cognito User Pools authenticated requests.
AppsyncIdentityIam
Identity information for IAM-authenticated requests.
AppsyncIdentityLambda
Identity information for Lambda-authorized requests.
AppsyncIdentityOidc
Identity information for OIDC-authenticated requests.
AppsyncResponse
Response structure returned to AWS AppSync from a Lambda resolver.
CognitoFederatedIdentity
Cognito Identity Pool information for federated IAM authentication
ID
A custom UUID-based identifier type for AppSync GraphQL objects.

Enums§

AppsyncAuthStrategy
Authorization strategy for AppSync operations.
AppsyncIdentity
Identity information for an AppSync request.
CognitoIdentityAuthType
Authentication type in a Cognito Identity Pool

Functions§

arg_from_json
Extracts and deserializes a named argument from a JSON Value into the specified type
res_to_json
Serializes a value into a JSON Value for AppSync responses

Attribute Macros§

appsync_operation
Marks an async function as an AWS AppSync resolver operation, binding it to a specific Query, Mutation or Subscription operation defined in the GraphQL schema.