Skip to content

Commit a66bd2b

Browse files
committed
First commit
1 parent ce33dcb commit a66bd2b

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

awslambdalistall-capi/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# AWS Lambda Function List Python example
2+
3+
This folder contains a Python application example that handles Lambda functions on AWS (Amazon Web Services).
4+
5+
List all Lambda functions and their information 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 bucket region changing the value of `REGION` variable in the code.
73+
74+
* Run the code.
75+
76+
Run application:
77+
78+
```bash
79+
python lambdalistall.py
80+
```
81+
82+
* Test the application.
83+
84+
You should see the list of all Lambda functions and their information.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
# lambdalistall.py
4+
# It is an example that handles Lambda functions on AWS.
5+
# It uses Client API (low-level) of Boto3.
6+
# List all Lambda functions and their information.
7+
8+
import sys
9+
import boto3
10+
import botocore
11+
12+
def main():
13+
14+
REGION = 'eu-west-1' # AWS region
15+
16+
# Create an Lambda Client
17+
lambdaclient = boto3.client('lambda', region_name=REGION)
18+
19+
# List lambda functions
20+
try:
21+
print('Listing functions ...')
22+
list_functions_resp = lambdaclient.list_functions()
23+
for function in list_functions_resp['Functions']:
24+
print('Function name: ', function['FunctionName'])
25+
print(' - ARN: ', function['FunctionArn'])
26+
print(' - Runtime: ', function['Runtime'])
27+
print(' - Role: ', function['Role'])
28+
print(' - Handler: ', function['Handler'])
29+
print(' - Description: ', function['Description'])
30+
print(' - Timeout: ', function['Timeout'])
31+
print(' - MemorySize: ', function['MemorySize'])
32+
print(' - LastModified: ', function['LastModified'])
33+
print(' - Description: ', function['Description'])
34+
print(' - CodeSize: ', function['CodeSize'])
35+
print(' - Version: ', function['Version'])
36+
37+
except botocore.exceptions.ClientError as e:
38+
raise
39+
40+
return
41+
42+
43+
# This is the standard boilerplate that calls the main() function.
44+
if __name__ == '__main__':
45+
main()

0 commit comments

Comments
 (0)