The following code examples show how to delete a Lambda function.
Note
The source code for these examples is in the AWS Code Examples GitHub repository. Have feedback on a code example? Create an Issue in the code examples repo.
SDK for Java 2.x
To learn how to set up and run this example, see GitHub.
public static void deleteLambdaFunction(LambdaClient awsLambda, String functionName) {
try {
DeleteFunctionRequest request = DeleteFunctionRequest.builder()
.functionName(functionName)
.build();
awsLambda.deleteFunction(request);
System.out.println("The "+functionName +" function was deleted");
} catch(LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
- For API details, see DeleteFunction in AWS SDK for Java 2.x API Reference.
SDK for Kotlin
This is prerelease documentation for a feature in preview release. It is subject to change.
To learn how to set up and run this example, see GitHub.
suspend fun delLambdaFunction(myFunctionName: String) {
val request = DeleteFunctionRequest {
functionName = myFunctionName
}
LambdaClient { region = "us-west-2" }.use { awsLambda ->
awsLambda.deleteFunction(request)
println("$myFunctionName was deleted")
}
}
- For API details, see DeleteFunction in AWS SDK for Kotlin API reference.
SDK for Python (Boto3)
To learn how to set up and run this example, see GitHub.
class LambdaWrapper:
def __init__(self, lambda_client, iam_resource):
self.lambda_client = lambda_client
self.iam_resource = iam_resource
def delete_function(self, function_name):
"""
Deletes a Lambda function.
:param function_name: The name of the function to delete.
"""
try:
self.lambda_client.delete_function(FunctionName=function_name)
except ClientError:
logger.exception("Couldn't delete function %s.", function_name)
raise
- For API details, see DeleteFunction in AWS SDK for Python (Boto3) API Reference.
For a complete list of AWS SDK developer guides and code examples, see Using Lambda with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.