quickwit-oss/quickwit · error · anyhow::Error

failed to create Lambda function '{}': {}

Error message

failed to create Lambda function '{}': {}

What it means

try_create_function calls the AWS Lambda CreateFunction API and wraps any AWS SDK error into an anyhow error prefixed with 'failed to create Lambda function'. The AWS error itself (permissions, existing conflict, invalid role ARN, package too large) is embedded in the message. It is thrown whenever the CreateFunction call returns Err rather than Ok.

Source

Thrown at quickwit/quickwit-lambda-client/src/deploy.rs:349

            let version = output
                .version()
                .ok_or_else(|| anyhow!("created function has no version number"))?
                .to_string();
            info!(
                function_name = %function_name,
                version = %version,
                "lambda function created and published"
            );
            Ok(Some(version))
        }
        Err(SdkError::ServiceError(err)) if err.err().is_resource_conflict_exception() => {
            debug!(
                function_name = %function_name,
                "lambda function already exists"
            );
            Ok(None)
        }
        Err(e) => Err(anyhow!(
            "failed to create Lambda function '{}': {}",
            function_name,
            e
        )),
    }
}

/// Update `$LATEST` to our embedded binary.
///
/// Returns the `code_sha256` of the uploaded code, to be used as a guard
/// when publishing the version (detects if another process overwrote `$LATEST`
/// between our update and publish).
async fn update_function_code(
    client: &LambdaClient,
    function_name: &str,
) -> anyhow::Result<String> {
    info!(
        function_name = %function_name,

View on GitHub (pinned to a39730c5cd)

Solutions

  1. Read the embedded AWS error in the message: if it is EntityAlreadyExists/ResourceConflictException, the function exists — call deploy_lambda_function again (it will take the update path) or delete the existing function.
  2. Verify the IAM execution role ARN exists and the caller credentials have lambda:CreateFunction and iam:PassRole.
  3. Check the deployment package size against Lambda quotas (50MB zipped direct upload / S3-based).
  4. Ensure the region configured for the client matches the region of the S3 code location.

Example fix

// before
Err(e) => Err(anyhow!("failed to create Lambda function '{}': {}", function_name, e))
// after: pre-check existence so the update path is taken
match client.create_function().send().await {
    Ok(_) => Ok(Some(code_sha256)),
    Err(e) if is_resource_conflict(&e) => update_function_code(client, function_name).await,
    Err(e) => Err(anyhow!("failed to create Lambda function '{}': {}", function_name, e)),
}
Defensive patterns

Strategy: try-catch

Validate before calling

aws iam simulate-principal-command --policy-source-arn <caller-arn> --action-names lambda:CreateFunction iam:PassRole
aws lambda get-function --function-name <name> 2>/dev/null && echo 'function already exists'

Try / catch

match deploy_lambda_function(...).await {
    Err(e) if e.to_string().contains("ResourceConflictException") => {
        // treat as: function exists, proceed with update path
    }
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: Calling deploy_lambda_function when the Lambda CreateFunction API fails: IAM execution role missing or lacking lambda:CreateFunction permission, function name already owned by the account/region, invalid zip deployment package, or exceeding the Lambda code size quota.

Common situations: First deployment of the searcher Lambda into a region where the role ARN is wrong; re-running deploy after a partial failure where the function already exists but creation returned an error; S3 code bucket in a different region than the function.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08). Data as JSON: /api/errors/3c4885618a36e194. Report an issue: GitHub.