Practice AWS Certification Question: AWS Solutions Architect Professional — Lambda — ECR

juan jose orjuela - Nov 3 - - Dev Community

When studying for an AWS certification, we often encounter questions that require a deep understanding of services we might not use every day. Understanding these services only at a theoretical level can lead to confusion and mistakes during the exam. So, how can we improve our comprehension and retention of these complex topics?

One of the best ways to tackle this challenge is by practicing directly with AWS services, replicating question scenarios in a real environment.

Services Associated with the Question: Lambda and ECR

Domain: Designing New Solutions

Question: Your team is developing a new Lambda function for a microservice component. You need to package and deploy the Lambda function as a container image. The container image must be based on the python:buster image with other dependencies and libraries installed. To use the container image correctly for the Lambda function, which of the following actions is necessary?

Answer: Install the runtime interface client in the container image to make it compatible with Lambda.

Related Services

AWS Lambda:

  • Description: Lambda is an AWS service that allows you to run code without provisioning or managing servers. This service supports multiple programming languages and, more recently, allows the use of container images as execution environments.

  • Relevant Features: When using Lambda with container images, it is essential to include a "runtime interface client" in the image. This client is an API within the container that enables Lambda to interact correctly with the runtime environment.

Amazon Elastic Container Registry (ECR):

  • Description: ECR is a fully managed container registry service that simplifies the storage, management, and deployment of Docker container images.

  • Relevant Features: Although it is not necessary to install an ECR agent in the container for this question, ECR is still relevant for storing and managing the container images that will be run on Lambda.

Practical Exercise to Demonstrate the Correct Answer

To test this configuration, you can follow these steps:

  1. Create a Dockerfile with the installation of the runtime interface client.
FROM python:buster

RUN pip install awslambdaric

WORKDIR /var/task

COPY app.py /var/task/

ENTRYPOINT ["python3", "-m", "awslambdaric"]

CMD ["app.handler"]
Enter fullscreen mode Exit fullscreen mode
  1. Create a basic handler for the Lambda execution.
import json

def handler(event, context):
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
Enter fullscreen mode Exit fullscreen mode
  1. Build the Docker image locally:
docker build -t lambda-container-demo .
Enter fullscreen mode Exit fullscreen mode

Image description

  1. Authenticate to the AWS account using environment variables:
export AWS_ACCESS_KEY_ID=mi-key
export AWS_SECRET_ACCESS_KEY=mi-secret
export AWS_DEFAULT_REGION=us-east-1
Enter fullscreen mode Exit fullscreen mode
  1. Create the repository in ECR to upload our image:
aws ecr create-repository --repository-name lambda-container-demo
Enter fullscreen mode Exit fullscreen mode
  1. Verify that it has been created in the ECR service from the console:

Image description

  1. Run the following commands to authenticate and upload the container:
#Inicia sesión en ECR, crea un repositorio y sube la imagen
aws ecr create-repository --repository-name lambda-container-demo
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <your_account_id>.dkr.ecr.us-east-1.amazonaws.com
docker tag lambda-container-demo:latest <your_account_id>.dkr.ecr.us-east-1.amazonaws.com/lambda-container-demo:latest
docker push <your_account_id>.dkr.ecr.us-east-1.amazonaws.com/lambda-container-demo:latest
Enter fullscreen mode Exit fullscreen mode
  1. Create a Lambda function based on this ECR image.

1

  1. Select the previously created image.

2

  1. Test the Lambda function to verify the expected behavior.

3

This concludes the practice for answering this AWS Architect Professional certification question.

Keep in mind that if you've never used ECR or Lambda with Docker images, in this practice you covered basic concepts that, by practicing, can help you retain them long-term.


If you've enjoyed this article, feel free to give a 👏.
🤔 Follow me on social media!

Thank you!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .