Deploy API module

This script automates the deployment of an AWS Lambda function using an ECR Image and integrates it with an API Gateway for HTTP/HTTPS access. The Deployment class handle the creation and configuration of the Lambda function and API Gateway.

The script uses environment variables for AWS credentials and Lambda configuration, and uses argparse to handle commandline arguments. This feature is important to automate the deploy using github actions, allowing to set the API endpoint as the output of this script and pass as argument the URI of an ECR Image and the name for the API gateway.

class deploy_API.Deployment(lambda_name, access_key_id, secret_access_key, region, lambda_role_arn, bucket)

Bases: object

Class to handle AWS Lmabda function deployment inside the ECR container and API Gateway integration.

create_API(api_gateway_name)

Creates an API Gateway with an HTTP POST endpoint to expose the Lambda function.

Sets up permissions to allow the API Gateway to invoke the Lambda function and generates a unique API Gateway endpoint URL for access.

Parameters:

api_gateway_namestr

The name of the API Gateway to be created.

create_lambda_function(image_uri)

Creates Lambda function using specified ECR image URI.

If the Lambda function already exists, it deletes the function before creating a new one. Configures the Lambda function with environment variables for S3 bucket access and AWS credentials.

Parameters:

image_uristr

The URI of the container image in ECR to be used for Lambda deployment.

Returns:

bool

True if the Lambda function creation is successful, False otherwise.

full_deploy(args)

Performs a full deployment process. Integration between lambda function and API.

Parameters:

argsNamespace

Parsed commandline arguments containing image_uri for the ECR URI and api_gateway for the API name.