|
| 1 | +# AWS Lambda Function Delete Python example |
| 2 | + |
| 3 | +This folder contains a Python application example that handles Lambda functions on AWS (Amazon Web Services). |
| 4 | + |
| 5 | +Delete a Lambda function using the Client API (low-level) of Boto 3. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +* You must have an [Amazon Web Services (AWS)](http://aws.amazon.com/) account. |
| 10 | + |
| 11 | +* The code was written for Python 3 and AWS SDK for Python (Boto3). |
| 12 | + |
| 13 | +* This example uses Client API (low-level) of Boto 3. |
| 14 | + |
| 15 | +* Install the AWS SDK for Python (Boto3). |
| 16 | + |
| 17 | + Install the latest Boto 3 release via pip: |
| 18 | + |
| 19 | + ```bash |
| 20 | + pip install boto3 |
| 21 | + ``` |
| 22 | + |
| 23 | +## Using the code |
| 24 | + |
| 25 | +* Configure your AWS access keys. |
| 26 | + |
| 27 | + **Important:** For security, it is strongly recommend that you use IAM users instead of the root account for AWS access. |
| 28 | + |
| 29 | + When you initialize a new service client without supplying any arguments, the AWS SDK for Java attempts to find AWS credentials by using the default credential provider chain. |
| 30 | + |
| 31 | + Setting your credentials for use by the AWS SDK for Java can be done in a number of ways, but here are the recommended approaches: |
| 32 | + |
| 33 | + * The default credential profiles file |
| 34 | + |
| 35 | + Set credentials in the AWS credentials profile file on your local system, located at: |
| 36 | + |
| 37 | + `~/.aws/credentials` on Linux, macOS, or Unix |
| 38 | + |
| 39 | + `C:\Users\USERNAME\.aws\credentials` on Windows |
| 40 | + |
| 41 | + This file should contain lines in the following format: |
| 42 | + |
| 43 | + ```bash |
| 44 | + [default] |
| 45 | + aws_access_key_id = <your_access_key_id> |
| 46 | + aws_secret_access_key = <your_secret_access_key> |
| 47 | + ``` |
| 48 | + Substitute your own AWS credentials values for the values `<your_access_key_id>` and `<your_secret_access_key>`. |
| 49 | + |
| 50 | + * Environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` |
| 51 | + |
| 52 | + Set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. |
| 53 | + |
| 54 | + To set these variables on Linux, macOS, or Unix, use `export`: |
| 55 | + |
| 56 | + ```bash |
| 57 | + export AWS_ACCESS_KEY_ID=<your_access_key_id> |
| 58 | + export AWS_SECRET_ACCESS_KEY=<your_secret_access_key> |
| 59 | + ``` |
| 60 | + |
| 61 | + To set these variables on Windows, use `set`: |
| 62 | + |
| 63 | + ```bash |
| 64 | + set AWS_ACCESS_KEY_ID=<your_access_key_id> |
| 65 | + set AWS_SECRET_ACCESS_KEY=<your_secret_access_key> |
| 66 | + ``` |
| 67 | + |
| 68 | +* You can create a Lambda function on AWS. |
| 69 | + |
| 70 | + You can use the AWS Lambda Function Hello World JSON Java example: [awslambdahellojson](/awslambdahellojson). |
| 71 | + |
| 72 | +* You can select the AWS region of the Lambda function changing the value of `REGION` variable in the code. |
| 73 | + |
| 74 | +* Run the code. |
| 75 | + |
| 76 | + You must provide 1 parameter: |
| 77 | + |
| 78 | + * `<FUNCTION_NAME>` = Lambda function name |
| 79 | + |
| 80 | + Run application: |
| 81 | + |
| 82 | + ```bash |
| 83 | + python lambdadelete.py function-name |
| 84 | + ``` |
| 85 | + |
| 86 | + You can use as name of the Lambda function 2 name formats: |
| 87 | + |
| 88 | + * Function name |
| 89 | + |
| 90 | + Ex.: `HelloJsonPython` |
| 91 | + |
| 92 | + * Function ARN |
| 93 | + |
| 94 | + Ex.: `arn:aws:lambda:eu-west-1:123456789012:function:HelloJsonPython` |
| 95 | + |
| 96 | + You can retrieve the function ARN by looking at the function in the AWS Console. |
| 97 | + |
| 98 | +* Test the application. |
| 99 | + |
| 100 | + The Lambda function is deleted and you should see the message "Deleted". |
0 commit comments