问题
I need to run a periodic cleanup on my EFS drive (which is being shared by multiple autoscaling EC2 instances). The cleanup involves deleting files/folders that meet a certain criterion (date/size etc.).
I imagined AWS Lambda to be the perfect solution for this task. Just trigger the function periodically, which should mount the Shared drive and run the cleanup. But it seems that Lambda only supports Creating/polling the disk for it's type and modifying its mountpoint etc.
Is there any alternative to accomplish this task?
回答1:
So far I've found that while direct file operations aren't supported by Lambda, it can spin up an EC2 instance, which can run a startup script to do the cleanup and then shutdown. While this solution is rather clunky, I do not see any alternative.
Lambda support for EFS seems to be a long standing demand:
Why can't you mount EFS to Lambda?
Can EFS be mounted from the Lambda environment
回答2:
what about mounting your EFS to an ec2 instance and use lambda to ssh into ec2 and do the cleaning. As an example, you can use python fabric library to ssh into the ec2.
回答3:
The solution with EC2 does not require the lambda at all. You can add an auto scaling group with scheduled policy to start instance once per week and shut it down. All activities required can be added using user data or some auto-run shell script in ec2 instance.
回答4:
AWS has released Lambda filesystem support. See these details for configuration information, including CloudFormation and SAM templates. The file system and the Lambda function must be in the same region, and the function must be attached to the VPC, though it may be in a different account.
来源:https://stackoverflow.com/questions/50924053/how-to-mount-efs-on-a-lambda-function