(config: &Deploy, metadata: &CargoMetadata)
| 37 | |
| 38 | #[tracing::instrument(target = "cargo_lambda")] |
| 39 | pub async fn run(config: &Deploy, metadata: &CargoMetadata) -> Result<()> { |
| 40 | tracing::trace!("deploying project"); |
| 41 | |
| 42 | if config.function_config.enable_function_url && config.function_config.disable_function_url { |
| 43 | return Err(miette::miette!( |
| 44 | "invalid options: --enable-function-url and --disable-function-url cannot be set together" |
| 45 | )); |
| 46 | } |
| 47 | |
| 48 | let progress = Progress::start("loading binary data"); |
| 49 | let (name, archive) = match load_archive(config, metadata) { |
| 50 | Ok(arc) => arc, |
| 51 | Err(err) => { |
| 52 | progress.finish_and_clear(); |
| 53 | return Err(err); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | let retry = RetryConfig::standard() |
| 58 | .with_retry_mode(RetryMode::Adaptive) |
| 59 | .with_max_attempts(3) |
| 60 | .with_initial_backoff(Duration::from_secs(5)); |
| 61 | |
| 62 | let remote_config = config.remote_config.clone().unwrap_or_default(); |
| 63 | let sdk_config = remote_config.sdk_config(Some(retry)).await; |
| 64 | |
| 65 | let result = if config.dry { |
| 66 | dry::DeployOutput::new(config, &name, &sdk_config, &archive).map(DeployResult::Dry) |
| 67 | } else if config.extension { |
| 68 | extensions::deploy(config, &name, &sdk_config, &archive, &progress) |
| 69 | .await |
| 70 | .map(DeployResult::Extension) |
| 71 | } else { |
| 72 | functions::deploy(config, &name, &sdk_config, &archive, &progress) |
| 73 | .await |
| 74 | .map(DeployResult::Function) |
| 75 | }; |
| 76 | |
| 77 | progress.finish_and_clear(); |
| 78 | let output = result?; |
| 79 | |
| 80 | match &config.output_format() { |
| 81 | OutputFormat::Text => println!("{output}"), |
| 82 | OutputFormat::Json => { |
| 83 | let text = to_string_pretty(&output) |
| 84 | .into_diagnostic() |
| 85 | .wrap_err("failed to serialize output into json")?; |
| 86 | println!("{text}") |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | Ok(()) |
| 91 | } |
| 92 | |
| 93 | fn load_archive(config: &Deploy, metadata: &CargoMetadata) -> Result<(String, BinaryArchive)> { |
| 94 | match &config.binary_path { |
nothing calls this directly
no test coverage detected