rusty_cdk_core/lambda/
dto.rs1use crate::{dto_methods, ref_struct};
2use crate::shared::Id;
3use crate::stack::Asset;
4use serde::Serialize;
5use serde_json::Value;
6use std::collections::HashMap;
7use crate::intrinsic::{get_arn, get_att, get_ref};
8
9pub struct FunctionRef {
11 id: Id,
12 resource_id: String,
13}
14
15impl FunctionRef {
16 pub fn new(id: Id, resource_id: String) -> Self {
17 Self { id, resource_id }
18 }
19
20 pub fn get_id(&self) -> &Id {
21 &self.id
22 }
23
24 pub fn get_resource_id(&self) -> &str {
25 self.resource_id.as_str()
26 }
27
28 pub fn get_ref(&self) -> Value {
29 crate::intrinsic::get_ref(self.get_resource_id())
30 }
31
32 pub fn get_arn(&self) -> Value {
33 crate::intrinsic::get_arn(self.get_resource_id())
34 }
35
36 pub fn get_att(&self, id: &str) -> Value {
37 crate::intrinsic::get_att(self.get_resource_id(), id)
38 }
39}
40
41#[derive(Debug, Serialize)]
42pub struct Function {
43 #[serde(skip)]
44 pub(super) id: Id,
45 #[serde(skip)]
46 pub(super) resource_id: String,
47 #[serde(skip)]
48 pub(crate) asset: Option<Asset>,
49 #[serde(rename = "Type")]
50 pub(super) r#type: String,
51 #[serde(rename = "Properties")]
52 pub(super) properties: LambdaFunctionProperties,
53}
54
55impl Function {
56 pub fn get_id(&self) -> &Id {
57 &self.id
58 }
59
60 pub fn get_resource_id(&self) -> &str {
61 self.resource_id.as_str()
62 }
63}
64
65#[derive(Debug, Serialize)]
66pub struct LambdaFunctionProperties {
67 #[serde(rename = "Code")]
68 pub(super) code: LambdaCode,
69 #[serde(rename = "MemorySize")]
70 pub(super) memory_size: u16,
71 #[serde(rename = "Timeout")]
72 pub(super) timeout: u16,
73 #[serde(rename = "Architectures")]
74 pub(super) architectures: Vec<String>,
75 #[serde(rename = "Role")]
76 pub(super) role: Value,
77 #[serde(rename = "Runtime", skip_serializing_if = "Option::is_none")]
78 pub(super) runtime: Option<String>,
79 #[serde(rename = "Handler", skip_serializing_if = "Option::is_none")]
80 pub(super) handler: Option<String>,
81 #[serde(rename = "FunctionName", skip_serializing_if = "Option::is_none")]
82 pub(super) function_name: Option<String>,
83 #[serde(rename = "Environment", skip_serializing_if = "Option::is_none")]
84 pub(super) environment: Option<Environment>,
85 #[serde(rename = "ReservedConcurrentExecutions", skip_serializing_if = "Option::is_none")]
86 pub(super) reserved_concurrent_executions: Option<u32>,
87 #[serde(rename = "LoggingConfig")]
88 pub(super) logging_info: LoggingInfo,
89 }
92
93#[derive(Debug, Serialize)]
94pub struct LambdaCode {
95 #[serde(rename = "S3Bucket", skip_serializing_if = "Option::is_none")]
96 pub(super) s3_bucket: Option<String>,
97 #[serde(rename = "S3Key", skip_serializing_if = "Option::is_none")]
98 pub(super) s3_key: Option<String>,
99 #[serde(rename = "ZipFile", skip_serializing_if = "Option::is_none")]
100 pub(super) zipfile: Option<String>,
101 }
105
106#[derive(Debug, Serialize)]
107pub struct Environment {
108 #[serde(rename = "Variables")]
109 pub(super) variables: HashMap<String, Value>,
110}
111
112#[derive(Debug, Serialize)]
113pub struct LoggingInfo {
114 #[serde(rename = "LogGroup")]
115 pub(super) log_group: Option<Value>,
116}
117
118ref_struct!(EventSourceMappingRef);
119
120#[derive(Debug, Serialize)]
121pub struct EventSourceMapping {
122 #[serde(skip)]
123 pub(super) id: Id,
124 #[serde(skip)]
125 pub(super) resource_id: String,
126 #[serde(rename = "Type")]
127 pub(super) r#type: String,
128 #[serde(rename = "Properties")]
129 pub(super) properties: EventSourceProperties,
130}
131dto_methods!(EventSourceMapping);
132
133#[derive(Debug, Serialize)]
134pub struct EventSourceProperties {
135 #[serde(rename = "EventSourceArn", skip_serializing_if = "Option::is_none")]
136 pub(super) event_source_arn: Option<Value>,
137 #[serde(rename = "FunctionName", skip_serializing_if = "Option::is_none")]
138 pub(super) function_name: Option<Value>,
139 #[serde(rename = "ScalingConfig", skip_serializing_if = "Option::is_none")]
140 pub(super) scaling_config: Option<ScalingConfig>,
141}
142
143#[derive(Debug, Serialize)]
144pub struct ScalingConfig {
145 #[serde(rename = "MaximumConcurrency")]
146 pub(super) max_concurrency: u16,
147}
148
149pub struct PermissionRef {
150 id: Id,
151 resource_id: String,
152}
153
154impl PermissionRef {
155 pub fn new(id: Id, resource_id: String) -> Self {
156 Self {
157 id,
158 resource_id
159 }
160 }
161
162 pub fn get_id(&self) -> Id {
163 self.id.clone()
164 }
165
166 pub fn get_resource_id(&self) -> &str {
167 self.resource_id.as_str()
168 }
169
170 pub fn get_ref(&self) -> Value {
171 get_ref(self.get_resource_id())
172 }
173
174 pub fn get_arn(&self) -> Value {
175 get_arn(self.get_resource_id())
176 }
177
178 pub fn get_att(&self, id: &str) -> Value {
179 get_att(self.get_resource_id(), id)
180 }
181}
182
183#[derive(Debug, Serialize)]
184pub struct Permission {
185 #[serde(skip)]
186 pub(super) id: Id,
187 #[serde(skip)]
188 pub(super) resource_id: String,
189 #[serde(rename = "Type")]
190 pub(super) r#type: String,
191 #[serde(rename = "Properties")]
192 pub(super) properties: LambdaPermissionProperties,
193}
194dto_methods!(Permission);
195
196#[derive(Debug, Serialize)]
197pub struct LambdaPermissionProperties {
198 #[serde(rename = "Action")]
199 pub(super) action: String,
200 #[serde(rename = "FunctionName")]
201 pub(super) function_name: Value,
202 #[serde(rename = "Principal")]
203 pub(super) principal: String,
204 #[serde(rename = "SourceArn", skip_serializing_if = "Option::is_none")]
205 pub(super) source_arn: Option<Value>,
206 #[serde(rename = "SourceAccount", skip_serializing_if = "Option::is_none")]
207 pub(super) source_account: Option<Value>,
208}