Lambda

Packaging AWS Lambda functions with large dependencies as containers

While the actual application code for many lambda functions might be small, in many (data science) usecases libraries used and to be packaged together push over the deployment package limit of 50 MB compressed. Container packaging to the rescue. A sample Dockerfile installing SageMaker Python SDK ARG WORK_DIR="/home/app/" FROM public.ecr.aws/lambda/python:3.8 ARG WORK_DIR RUN pip install wheel sagemaker COPY main.py . WORKDIR ${WORK_DIR} CMD ["main.handler"] and corresponding main.py import sagemaker import sys def handler(event, context): print(sys.

AWS Lambda Lookup AccountId and Region

For a number of uses including generating IAM roles and various policies, lambda code might require access to current account id and region. Here is a code snippet on how to acquire those values: import json import logging import boto3 logger = logging.getLogger() logger.setLevel(logging.INFO) def lambda_handler(event, context): logger.info(json.dumps(event)) account_id = boto3.client('sts').get_caller_identity().get('Account') # use a client which is region based logs_client = boto3.client('logs') region_name = logs_client.meta.region_name logger.info(f"{account_id}:{region_name}")