Skip to content

Getting Started

After you installed this package, the next step is to import the package into your code and start using the functions.

from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin

As a demonstration of the library, let's build a simple example together that will do something cool .

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/config
[default]
region=<region_code>
# ~/.aws/credentials
[default]
aws_access_key_id=<your_aws_access_key_id>
aws_secret_access_key=<your_aws_secret_access_key>
aws = BotAWSLambdaPlugin()

2. Passing credentials in the class constructor.

aws = 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>'  # default-region='us-east-1'
)

Lambda operations

List all functions

from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin

aws = BotAWSLambdaPlugin()
print(aws.list_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).

from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin

aws = BotAWSLambdaPlugin()
print(aws.get_function(function_name='<lambda_name>'))

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

from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin

aws = BotAWSLambdaPlugin()
result = aws.invoke_function(function_name='<lambda_name>', payload={'name': 'Botcity'})
print(result)

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.

from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin

aws = BotAWSLambdaPlugin()
print(aws.list_aliases(function_name='<lambda_name>'))

Get alias

from botcity.plugins.aws.lambda_functions import BotAWSLambdaPlugin

aws = BotAWSLambdaPlugin()
print(aws.get_alias(function_name='<lambda_name>', alias_name='<alias_name>'))

Next Steps

Check our examples and experiment with the API. Let us know where it can be improved.

Have fun automating!

Back to top