{"record":{"id":"3c4885618a36e194","repo":"quickwit-oss/quickwit","slug":"failed-to-create-lambda-function","errorCode":null,"errorMessage":"failed to create Lambda function '{}': {}","messagePattern":"failed to create Lambda function '(.+?)': (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-lambda-client/src/deploy.rs","lineNumber":349,"sourceCode":"            let version = output\n                .version()\n                .ok_or_else(|| anyhow!(\"created function has no version number\"))?\n                .to_string();\n            info!(\n                function_name = %function_name,\n                version = %version,\n                \"lambda function created and published\"\n            );\n            Ok(Some(version))\n        }\n        Err(SdkError::ServiceError(err)) if err.err().is_resource_conflict_exception() => {\n            debug!(\n                function_name = %function_name,\n                \"lambda function already exists\"\n            );\n            Ok(None)\n        }\n        Err(e) => Err(anyhow!(\n            \"failed to create Lambda function '{}': {}\",\n            function_name,\n            e\n        )),\n    }\n}\n\n/// Update `$LATEST` to our embedded binary.\n///\n/// Returns the `code_sha256` of the uploaded code, to be used as a guard\n/// when publishing the version (detects if another process overwrote `$LATEST`\n/// between our update and publish).\nasync fn update_function_code(\n    client: &LambdaClient,\n    function_name: &str,\n) -> anyhow::Result<String> {\n    info!(\n        function_name = %function_name,","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-lambda-client/src/deploy.rs#L331-L367","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Verify the IAM execution role ARN exists and the caller credentials have lambda:CreateFunction and iam:PassRole.","Check the deployment package size against Lambda quotas (50MB zipped direct upload / S3-based).","Ensure the region configured for the client matches the region of the S3 code location."],"exampleFix":"// before\nErr(e) => Err(anyhow!(\"failed to create Lambda function '{}': {}\", function_name, e))\n// after: pre-check existence so the update path is taken\nmatch client.create_function().send().await {\n    Ok(_) => Ok(Some(code_sha256)),\n    Err(e) if is_resource_conflict(&e) => update_function_code(client, function_name).await,\n    Err(e) => Err(anyhow!(\"failed to create Lambda function '{}': {}\", function_name, e)),\n}","handlingStrategy":"try-catch","validationCode":"aws iam simulate-principal-command --policy-source-arn <caller-arn> --action-names lambda:CreateFunction iam:PassRole\naws lambda get-function --function-name <name> 2>/dev/null && echo 'function already exists'","typeGuard":null,"tryCatchPattern":"match deploy_lambda_function(...).await {\n    Err(e) if e.to_string().contains(\"ResourceConflictException\") => {\n        // treat as: function exists, proceed with update path\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Pre-check function existence with get-function before deploying.","Grant lambda:CreateFunction and iam:PassRole to the deploying principal.","Pin the AWS region for both the Lambda client and the S3 code bucket."],"tags":["aws","lambda","deployment","iam"],"backgroundTag":"http-error-response","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}