Architecture Overview
- AWS Services
- AWS Lambda
- AWS API Gateway
- Amazon SQS
- Amazon S3
Architecture Diagram
+-------------------+
| API Gateway |
+-------------------+
|
v
+-------------------+
| Lambda Function |
+-------------------+
|
v
+-------------------+
| Amazon SQS |
+-------------------+
|
v
+-------------------+
| Amazon S3 |
+-------------------+
Components
- API Gateway
- The REST API endpoint is used to trigger the on-demand job.
- Integrated with Lambda function.
- Lambda Function
- Runs the on-demand job.
- Processes messages from the SQS queue.
- Stores output in an S3 bucket.
- Amazon SQS
- Message queue for job requests.
- The lambda function polls the SQS queue for new messages.
- Amazon S3
- Stores output files from the Lambda function
Steps to integrate with lambda function
Step 1. Create API Gateway.
- Log in to the AWS Management Console
- Navigate to API Gateway
- Create REST API
- Create a POST method for triggering on-demand job
- Integrate with the Lambda function
Step 2. Create a Lambda Function.
- Navigate to Lambda
- Create a new function
- Choose Node.js or Python runtime
- Set handler function
- Configure environment variables
- Set timeout and memory limits
Step 3. Create SQS Queue.
- Navigate to SQS
- Create a new queue
- Configure queue settings
Step 4. Configure Lambda Function to Poll SQS Queue.
- Navigate to Lambda
- Configure event source mapping
- Choose the SQS queue
Step 5. Create S3 Bucket.
- Navigate to S3
- Create a new bucket
- Configure bucket settings
Step 6. Test On-Demand Job.
- Send a POST request to API Gateway
- Verify Lambda function execution
- Check output files in the S3 bucket
Lambda Function (Node.js)
const AWS = require('aws-sdk');
const sqs = new AWS.SQS({ region: 'us-west-2' });
const s3 = new AWS.S3({ region: 'us-west-2' });
exports.handler = async (event) => {
const message = JSON.parse(event.body);
const jobId = message.jobId;
const output = await processJob(jobId);
await s3.putObject({
Bucket: 'my-bucket',
Key: `${jobId}.txt`,
Body: output,
}).promise();
};
const processJob = async (jobId) => {
// Job processing logic here
return `Job ${jobId} completed`;
};
{
"jobId": "$input.params('jobId')"
}