Create AWS Lambda function with handler
✓Works with OpenClaudeYou are an AWS developer. The user wants to create an AWS Lambda function with a handler that responds to events and can be deployed and tested.
What to check first
- Run
aws --versionto confirm AWS CLI is installed and configured - Verify IAM permissions include
lambda:CreateFunction,lambda:UpdateFunction, andiam:PassRole - Check that you have an execution role ARN ready or create one with
aws iam create-role --role-name lambda-execution-role --assume-role-policy-document file://trust-policy.json
Steps
- Create a
trust-policy.jsonfile that allows Lambda to assume the role: include"Service": "lambda.amazonaws.com"in the principal - Create the execution role with appropriate permissions (attach
AWSLambdaBasicExecutionRolefor CloudWatch logs) - Write your handler function in a file like
index.jsorlambda_function.pywith the correct function signature for your runtime - Create a
deployment.zipfile containing only your handler code:zip deployment.zip index.js(do not include node_modules or venv) - Use
aws lambda create-functionwith--handler,--role,--runtime, and--zip-fileparameters - Test the function locally with
aws lambda invoke --function-name <name> --payload '{}' response.json - View logs in CloudWatch with
aws logs tail /aws/lambda/<function-name> --follow - Update the function code with
aws lambda update-function-code --function-name <name> --zip-file fileb://deployment.zipafter changes
Code
// index.js - Lambda handler for Node.js 18.x
exports.handler = async (event, context) => {
console.log('Event received:', JSON.stringify(event, null, 2));
try {
// Extract data from event
const body = event.body ? JSON.parse(event.body) : event;
const name = body.name || 'World';
// Process the request
const message = `Hello, ${name}!`;
// Return response in API Gateway format
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: message,
timestamp: new Date().toISOString(),
requestId: context.requestId
})
};
} catch (error) {
console.error('Error processing request:', error);
return {
statusCode: 500,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
error: 'Internal server error',
message: error.message
})
};
}
};
// AWS CLI deployment script (deploy.sh)
#!/bin/bash
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Cloud (AWS/GCP/Azure) Skills
Other Claude Code skills in the same category — free to download.
S3 Operations
Set up S3 bucket operations (upload, download, presigned URLs)
DynamoDB CRUD
Create DynamoDB CRUD operations
SQS Setup
Set up SQS queue producer and consumer
SNS Notifications
Configure SNS for push notifications
CloudFront Setup
Set up CloudFront CDN distribution
Cognito Auth
Implement AWS Cognito authentication
RDS Setup
Configure RDS database connection
ECS Task Definition
Create ECS task definitions
Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.