MCPcopy Create free account
hub / github.com/cargo-lambda/cargo-lambda / upsert_function

Function upsert_function

crates/cargo-lambda-deploy/src/functions.rs:116–175  ·  view source on GitHub ↗
(
    config: &Deploy,
    name: &str,
    client: &LambdaClient,
    sdk_config: &SdkConfig,
    binary_archive: &BinaryArchive,
    progress: &Progress,
)

Source from the content-addressed store, hash-verified

114
115#[allow(clippy::too_many_arguments)]
116async fn upsert_function(
117 config: &Deploy,
118 name: &str,
119 client: &LambdaClient,
120 sdk_config: &SdkConfig,
121 binary_archive: &BinaryArchive,
122 progress: &Progress,
123) -> Result<(String, String)> {
124 let current_function = client.get_function().function_name(name).send().await;
125
126 let action = match current_function {
127 Ok(fun) => FunctionAction::Update(Box::new(fun)),
128 Err(no_fun) if function_doesnt_exist_error(&no_fun) => FunctionAction::Create,
129 Err(no_fun) => {
130 return Err(no_fun)
131 .into_diagnostic()
132 .wrap_err("failed to fetch lambda function");
133 }
134 };
135
136 let s3_client = S3Client::new(sdk_config);
137
138 let (arn, version) = match action {
139 FunctionAction::Create => {
140 let function_role = match &config.function_config.role {
141 None => roles::create(config, sdk_config, progress).await?,
142 Some(role) => FunctionRole::from_existing(role.clone()),
143 };
144
145 create_function(
146 config,
147 name,
148 client,
149 &s3_client,
150 binary_archive,
151 progress,
152 function_role,
153 )
154 .await?
155 }
156 FunctionAction::Update(fun) => {
157 progress.set_message("deploying function");
158
159 let conf = fun
160 .configuration
161 .ok_or_else(|| miette::miette!("missing function configuration"))?;
162
163 let function_arn = update_function_config(config, name, client, progress, conf).await?;
164
165 tag_function(client, config.lambda_tags(), function_arn).await?;
166
167 update_function_code(config, name, client, &s3_client, binary_archive, progress).await?
168 }
169 };
170
171 Ok((
172 arn.expect("missing function ARN"),
173 version.expect("missing function version"),

Callers 1

deployFunction · 0.85

Calls 9

newFunction · 0.85
createFunction · 0.85
create_functionFunction · 0.85
update_function_configFunction · 0.85
tag_functionFunction · 0.85
update_function_codeFunction · 0.85
set_messageMethod · 0.80
lambda_tagsMethod · 0.80

Tested by

no test coverage detected