app.py
from chalice import Chalice
import threading
import time
from datetime import datetime
app = Chalice(app_name='multithread-test')
app.debug = True
def run_thread(msg):
app.log.debug(f"Call {msg} and sleep, timestamp {datetime.now()}")
time.sleep(5)
@app.lambda_function(name='multithread-test')
def handler(event, context):
thread_list = list()
for i in range(0, 5):
msg = f'thread-{i}'
thread = threading.Thread(target=run_thread, args=(msg,))
thread_list.append(thread)
thread.start()
for t in thread_list:
t.join()
return "Done!"
- Create AWS chalice new project
β‘ $ chalice new-project multithread-test
- Deploy function
β‘ $ chalice deploy
Creating deployment package.
Creating IAM role: multithread-test-dev
Creating lambda function: multithread-test-dev-multithread-test
Resources deployed:
- Lambda ARN: arn:aws:lambda:ap-northeast-2:1111111111111:function:multithread-test-dev-multithread-test
π Run test
- Invoke lambda function using aws-cli
β‘ $ aws lambda invoke --function-name multithread-test-dev-multithread-test --region ap-northeast-2 outfile
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
π Check result
Read More
- Pelican-resume with docker-compose and AWS + CDK
- Using Helm Install Botkube Integrate With Slack On EKS
- Ansible AWS EC2 Dynamic Inventory Plugin
- How To List All Enabled Regions Within An AWS account
- Using AWS KMS In AWS Lambda
- Create AWS Backup Plan
- Techniques For Writing Least Privilege IAM Policies
- EKS Persistent Storage With EFS Amazon Service
- Create k8s Cronjob To Schedule Delete Expired Files
- Amazon ECR - Lifecycle Policy Rules
- Connect Postgres Database Using Lambda Function
- Using SourceIp in ALB Listener Rule
- Amazon Simple Systems Manager (SSM)
- Invalidation AWS CDN Using Boto3
- Create AWS Lambda Function Triggered By S3 Notification Event
- CI/CD Of Invalidation AWS CDN Using Gitlab Pipeline
- Create CodeDeploy
- Gitlab Pipeline With AWS Codedeploy
- Create AWS-CDK image container
- Deploy Python Lambda Functions With Container Image
- Custom CloudWatch Events
- How To Get Lastest Image Version in AWS ECR