我有一个 python 脚本,它获取 N 张图像并将其转换为一张全景图像。
工作流程如下:
- 通过 Web 界面将 n 个图像上传到 s3
- 这应该会触发 EC2 实例启动并运行脚本
- 将图像从 S3 复制到本地实例存储
- 执行脚本后,将结果复制到 S3存储桶
- 脚本竞争它已显示在网络上。
- 结果可以从网上下载
在此过程中,上传图片后如何启动实例?我怎么知道它执行了脚本?
我需要关于 2 和 5 的帮助。如何实施?我应该使用任何其他 AWS 服务吗?
注意:我不需要 lambda。
I have a python script that takes an N number of images and converts it to one panorama image.
The workflow is below:
- upload n number of images to s3 via the web interface
- This should trigger the EC2 instance to start and run the script
- Copy images from the S3 to local instance storage
- Once the script is executed, then copy the result to the S3 bucket
- Script competes it has shown to the web.
- Result downloadable from the web
In this process, how can I start the instance once I uploaded the images? How can I know it executed the script?
I need help on the 2 and 5. How to implement it? Should I use any other AWS Services?
Note: I don’t need lambda.
发布评论
评论(1)
如果经常转换映像,那么传统体系结构将是:
过程只有很少处理图像,您需要启动/停止EC2实例来处理图像,那么架构将是:
startInstances()
打开已经创建并已加载所有必要软件的EC2实例。 (或者,如果您有一个正在控制该过程的Web应用程序,则可以启动EC2实例,并且不需要lambda函数。)/var/var/lib/lib/cloud/scripts/scripts/script中的EC2实例上的任何脚本当实例是 start 时,每启动/
将自动运行(请注意,这与仅在实例的第一个启动上运行的用户数据脚本不同)。脚本应从S3存储键中获取文件,并在处理完成后处理图像sudo shotdown关闭EC2实例现在-h
,但是,以上是异步过程。也就是说,Web应用程序(或lambda函数)启动了实例,但是没有返回“响应”。您将需要一些机制才能“知道”该实例已经完成工作。这可能就像在S3存储桶中查找具有特定名称的输出文件一样简单。此名称可以从输入映像的名称派生,也许您的应用程序在S3中创建一个配置文件,其中包含输入映像的文件名,还指定了输出图像的文件名。
因此,您的步骤5(“脚本竞争它已显示给网络”)可能需要网页每15秒检查一次结果,而不是简单地在发生时'显示'结果。
另请参阅:
If you are frequently converting images, then the traditional architecture would be:
However, if you are only rarely processing images and you need to start/stop the EC2 instance to process the images, then the architecture would be:
StartInstances()
to turn on an EC2 instance that has already been created and has all necessary software loaded. (Alternatively, if you have a web app that is controlling the process, it can start the EC2 instance and the Lambda function is not required.)/var/lib/cloud/scripts/per-boot/
will automatically run when the instance is started (note that this is different to User Data scripts that only run on the first boot of an instance). The script should grab the files from the S3 bucket and process the imagesudo shutdown now -h
However, the above is an asynchronous process. That is, the web app (or Lambda function) starts the instance, but no 'response' is returned. You will need some mechanism to 'know' that the instance has finished its job. This could be as simple as looking in the S3 bucket for an output file with a particular name. This name could be derived from the names of the input images, or perhaps your app creates a configuration file in S3 that contains the filenames of the input images and also specifies the filename for the output image.
Therefore, your Step 5 ("Script competes it has shown to the web") will probably need the web page to check for a result every 15 seconds, rather than simply 'showing' a result when it happens.
See also: Auto-Stop EC2 instances when they finish a task - DEV Community