Skip to main content

aws_lambda_events/event/lambda_function_urls/
mod.rs

1#[cfg(feature = "builders")]
2use bon::Builder;
3use http::HeaderMap;
4use serde::{Deserialize, Serialize};
5#[cfg(feature = "catch-all-fields")]
6use serde_json::Value;
7use std::collections::HashMap;
8
9use crate::custom_serde::{deserialize_nullish, serialize_headers};
10
11/// `LambdaFunctionUrlRequest` contains data coming from the HTTP request to a Lambda Function URL.
12#[non_exhaustive]
13#[cfg_attr(feature = "builders", derive(Builder))]
14#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
15#[serde(rename_all = "camelCase")]
16pub struct LambdaFunctionUrlRequest {
17    /// Version is expected to be `"2.0"`
18    #[serde(default)]
19    pub version: Option<String>,
20    #[serde(default)]
21    pub raw_path: Option<String>,
22    #[serde(default)]
23    pub raw_query_string: Option<String>,
24    pub cookies: Option<Vec<String>>,
25    #[serde(deserialize_with = "http_serde::header_map::deserialize", default)]
26    #[serde(serialize_with = "serialize_headers")]
27    pub headers: HeaderMap,
28    #[serde(deserialize_with = "deserialize_nullish")]
29    #[serde(default)]
30    pub query_string_parameters: HashMap<String, String>,
31    pub request_context: LambdaFunctionUrlRequestContext,
32    pub body: Option<String>,
33    pub is_base64_encoded: bool,
34    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
35    /// Enabled with Cargo feature `catch-all-fields`.
36    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
37    #[cfg(feature = "catch-all-fields")]
38    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
39    #[serde(flatten)]
40    #[cfg_attr(feature = "builders", builder(default))]
41    pub other: serde_json::Map<String, Value>,
42}
43
44/// `LambdaFunctionUrlRequestContext` contains the information to identify the AWS account and resources invoking the Lambda function.
45#[non_exhaustive]
46#[cfg_attr(feature = "builders", derive(Builder))]
47#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
48#[serde(rename_all = "camelCase")]
49pub struct LambdaFunctionUrlRequestContext {
50    #[serde(default)]
51    pub account_id: Option<String>,
52    #[serde(default)]
53    pub request_id: Option<String>,
54    pub authorizer: Option<LambdaFunctionUrlRequestContextAuthorizerDescription>,
55    /// APIID is the Lambda URL ID
56    #[serde(default)]
57    #[serde(rename = "apiId")]
58    pub apiid: Option<String>,
59    /// DomainName is of the format `"<url-id>.lambda-url.<region>.on.aws"`
60    #[serde(default)]
61    pub domain_name: Option<String>,
62    /// DomainPrefix is the Lambda URL ID
63    #[serde(default)]
64    pub domain_prefix: Option<String>,
65    #[serde(default)]
66    pub time: Option<String>,
67    pub time_epoch: i64,
68    pub http: LambdaFunctionUrlRequestContextHttpDescription,
69    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
70    /// Enabled with Cargo feature `catch-all-fields`.
71    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
72    #[cfg(feature = "catch-all-fields")]
73    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
74    #[serde(flatten)]
75    #[cfg_attr(feature = "builders", builder(default))]
76    pub other: serde_json::Map<String, Value>,
77}
78
79/// `LambdaFunctionUrlRequestContextAuthorizerDescription` contains authorizer information for the request context.
80#[non_exhaustive]
81#[cfg_attr(feature = "builders", derive(Builder))]
82#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
83#[serde(rename_all = "camelCase")]
84pub struct LambdaFunctionUrlRequestContextAuthorizerDescription {
85    pub iam: Option<LambdaFunctionUrlRequestContextAuthorizerIamDescription>,
86    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
87    /// Enabled with Cargo feature `catch-all-fields`.
88    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
89    #[cfg(feature = "catch-all-fields")]
90    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
91    #[serde(flatten)]
92    #[cfg_attr(feature = "builders", builder(default))]
93    pub other: serde_json::Map<String, Value>,
94}
95
96/// `LambdaFunctionUrlRequestContextAuthorizerIamDescription` contains IAM information for the request context.
97#[non_exhaustive]
98#[cfg_attr(feature = "builders", derive(Builder))]
99#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
100#[serde(rename_all = "camelCase")]
101pub struct LambdaFunctionUrlRequestContextAuthorizerIamDescription {
102    #[serde(default)]
103    pub access_key: Option<String>,
104    #[serde(default)]
105    pub account_id: Option<String>,
106    #[serde(default)]
107    pub caller_id: Option<String>,
108    #[serde(default)]
109    pub user_arn: Option<String>,
110    #[serde(default)]
111    pub user_id: Option<String>,
112    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
113    /// Enabled with Cargo feature `catch-all-fields`.
114    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
115    #[cfg(feature = "catch-all-fields")]
116    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
117    #[serde(flatten)]
118    #[cfg_attr(feature = "builders", builder(default))]
119    pub other: serde_json::Map<String, Value>,
120}
121
122/// `LambdaFunctionUrlRequestContextHttpDescription` contains HTTP information for the request context.
123#[non_exhaustive]
124#[cfg_attr(feature = "builders", derive(Builder))]
125#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
126#[serde(rename_all = "camelCase")]
127pub struct LambdaFunctionUrlRequestContextHttpDescription {
128    #[serde(default)]
129    pub method: Option<String>,
130    #[serde(default)]
131    pub path: Option<String>,
132    #[serde(default)]
133    pub protocol: Option<String>,
134    #[serde(default)]
135    pub source_ip: Option<String>,
136    #[serde(default)]
137    pub user_agent: Option<String>,
138    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
139    /// Enabled with Cargo feature `catch-all-fields`.
140    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
141    #[cfg(feature = "catch-all-fields")]
142    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
143    #[serde(flatten)]
144    #[cfg_attr(feature = "builders", builder(default))]
145    pub other: serde_json::Map<String, Value>,
146}
147
148/// `LambdaFunctionUrlResponse` configures the HTTP response to be returned by Lambda Function URL for the request.
149#[non_exhaustive]
150#[cfg_attr(feature = "builders", derive(Builder))]
151#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
152#[serde(rename_all = "camelCase")]
153pub struct LambdaFunctionUrlResponse {
154    pub status_code: i64,
155    #[serde(deserialize_with = "http_serde::header_map::deserialize", default)]
156    #[serde(serialize_with = "serialize_headers")]
157    pub headers: HeaderMap,
158    #[serde(default)]
159    pub body: Option<String>,
160    pub is_base64_encoded: bool,
161    pub cookies: Vec<String>,
162    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
163    /// Enabled with Cargo feature `catch-all-fields`.
164    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
165    #[cfg(feature = "catch-all-fields")]
166    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
167    #[serde(flatten)]
168    #[cfg_attr(feature = "builders", builder(default))]
169    pub other: serde_json::Map<String, Value>,
170}