-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathlambdalist.py
67 lines (54 loc) · 2.16 KB
/
lambdalist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- coding: utf-8 -*-
# lambdalist.py
# It is an example that handles Lambda functions on AWS.
# It uses Client API (low-level) of Boto3.
# List information of a Lambda function.
# You must provide 1 parameter:
# FUNCTION_NAME = Lambda function name
import sys
import boto3
import botocore
def main():
REGION = 'eu-west-1' # AWS region
# Make a list of command line arguments, omitting the [0] element
# which is the script itself.
args = sys.argv[1:]
if len(args) < 1:
print('Not enough parameters.\n'\
'Proper Usage is: python lambdalist.py <FUNCTION_NAME>')
sys.exit(1)
function_name = args[0]
print('Lambda function name: ' + function_name)
# Create a Lambda Client
lambda_client = boto3.client('lambda', region_name=REGION)
# List lambda function configuration
try:
print('Listing function ...')
config = lambda_client.get_function_configuration(
FunctionName=function_name)
print('Function name: ', config['FunctionName'])
print(' - ARN: ', config['FunctionArn'])
print(' - Runtime: ', config['Runtime'])
print(' - Role: ', config['Role'])
print(' - Handler: ', config['Handler'])
print(' - Description: ', config['Description'])
print(' - Timeout: ', config['Timeout'])
print(' - MemorySize: ', config['MemorySize'])
print(' - LastModified: ', config['LastModified'])
print(' - Description: ', config['Description'])
print(' - CodeSize: ', config['CodeSize'])
print(' - Version: ', config['Version'])
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "ResourceNotFoundException":
print("Error: Function Not Found!!")
elif e.response['Error']['Code'] == "AccessDeniedException":
print("Error: Access Denied!!")
elif e.response['Error']['Code'] == "ValidationException":
print("Error: Name Not Valid!!")
else:
raise
return
# This is the standard boilerplate that calls the main() function.
if __name__ == '__main__':
main()