Amazon AWS - Lambda¶
Nothing can be simpler to interact with Lambda Funtions than the BotCity plugin for AWS Lambda.
Manage synchronous and asynchronous invocations of lambda functions.
Installation¶
Importing the Plugin¶
After you installed this package, the next step is to import the package into your code and start using the functions.
Setting up connection¶
Note
There are two different ways to authenticate.
1. Creating the .aws
folder in the home directory, you need to create two files.
# ~/.aws/credentials
[default]
aws_access_key_id=<your_aws_access_key_id>
aws_secret_access_key=<your_aws_secret_access_key>
2. Passing credentials in the class constructor.
# Using the `.aws` folder
lambda_funtion = BotAWSLambdaPlugin()
# Alternative using the credentials as constructor arguments
lambda_funtion = BotAWSLambdaPlugin(
use_credentials_file=False,
access_key_id='<your_aws_access_key_id>',
secret_access_key='<your_aws_secret_access_key>',
region_name='<region_code>'
)
Lambda operations¶
List all functions¶
Get function info¶
Info
The function name
parameter can be name-only or name with alias.
my-function
(name-only), my-function:v1
(with alias).
Lambda invocation¶
Synchronous invocation¶
The function name
parameter value
The function name
parameter can be name-only or name with alias.
my-function
(name-only), my-function:v1
(with alias).
InvocationType
You can use the InvocationType='Event'
parameter to invoke lambda asynchronously,
but you don't receive the response value
Asynchronous invocation¶
Return type
The future_invoke_function
function returns a concurrent.futures.Future instance.
import time
from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin
aws = BotAWSLambdaPlugin()
future_result = aws.future_invoke_function(function_name='<lambda_name>', payload={'name': 'Botcity'})
while not future_result.done():
print('waiting...')
time.sleep(1)
print('Invoke (result): ', future_result.result())
Alias operation¶
List aliases¶
Info
The function name
parameter is name-only.