
Ultimate access to all questions.
Answer-first summary for fast verification
Answer: Copy the code into an AWS Lambda function that has 1 GB of memory. Create an Amazon EventBridge scheduled rule to run the code each hour.
## Explanation **Correct Answer: B** **Why Option B is correct:** 1. **Cost Optimization**: Lambda is serverless and charges only for the execution time (10 seconds per hour). With Lambda, you pay only for the compute time consumed, which is minimal for a job that runs for just 10 seconds every hour. 2. **Memory Requirement**: The job consumes 1 GB of memory, which Lambda supports. 3. **Scheduling**: Amazon EventBridge can trigger Lambda functions on a schedule (every hour). 4. **No idle costs**: Unlike EC2 or Fargate, there are no costs when the function is not running. 5. **Java Support**: Lambda supports Java runtime. **Why other options are incorrect:** **Option A (Fargate):** - Fargate charges for the entire time the task is running, not just execution time. Even though you could use 0.5 vCPU and 1 GB memory, you'd pay for the full hour between jobs. - Fargate has a minimum billing duration of 1 minute, so you'd pay for at least 1 minute per execution. - More expensive than Lambda for short, infrequent jobs. **Option C (Container on EC2 with AMI):** - Still requires an EC2 instance running continuously or being started/stopped. - Complex solution that doesn't optimize costs as effectively as Lambda. - Requires managing the container lifecycle and scheduling. **Option D (Stop/Start EC2 instance):** - While stopping EC2 instances saves compute costs, you still pay for EBS storage. - There's overhead in starting/stopping instances (boot time, potential delays). - Not as cost-effective as serverless Lambda for such short jobs. **Key AWS Concepts:** - **AWS Lambda**: Serverless compute service that runs code in response to events and automatically manages the underlying compute resources. - **Amazon EventBridge**: Serverless event bus service that can schedule Lambda functions. - **Cost Optimization Principle**: Use serverless services for short, infrequent workloads to avoid paying for idle resources. **Cost Comparison:** - Lambda: Pay for 10 seconds of execution every hour (very low cost) - EC2/Fargate: Pay for resources allocated continuously or for minimum billing periods This solution provides the best cost optimization while meeting all functional requirements.
Author: LeetQuiz Editorial Team
No comments yet.
A company runs a Java-based job on an Amazon EC2 instance. The job runs every hour and takes 10 seconds to run. The job runs on a scheduled interval and consumes 1 GB of memory. The CPU utilization of the instance is low except for short surges during which the job uses the maximum CPU available. The company wants to optimize the costs to run the job.
Which solution will meet these requirements?
A
Use AWS App2Container (A2C) to containerize the job. Run the job as an Amazon Elastic Container Service (Amazon ECS) task on AWS Fargate with 0.5 virtual CPU (vCPU) and 1 GB of memory.
B
Copy the code into an AWS Lambda function that has 1 GB of memory. Create an Amazon EventBridge scheduled rule to run the code each hour.
C
Use AWS App2Container (A2C) to containerize the job. Install the container in the existing Amazon Machine Image (AMI). Ensure that the schedule stops the container when the task finishes.
D
Configure the existing schedule to stop the EC2 instance at the completion of the job and restart the EC2 instance when the next job starts.