如何使用CloudFormation自动在AWS EC2上安装Anaconda

 2023-09-06 阅读 23 评论 0

摘要:by Daniel Barker 丹尼尔巴克(Daniel Barker) 如何使用CloudFormation自动在AWS EC2上安装Anaconda (How to automate Anaconda installs on AWS EC2 with CloudFormation) TL; DR (TL;DR) Are you struggling to automate the install of Anaconda on AWS (Amazon Web Servic

by Daniel Barker

丹尼尔·巴克(Daniel Barker)

如何使用CloudFormation自动在AWS EC2上安装Anaconda (How to automate Anaconda installs on AWS EC2 with CloudFormation)

TL; DR (TL;DR)

Are you struggling to automate the install of Anaconda on AWS (Amazon Web Services) EC2 instances and install necessary Python packages for your project? I was — so I wrote a simple bash script to handle it.

您是否正在努力在AWS(Amazon Web Services)EC2实例上自动化Anaconda的安装并为您的项目安装必要的Python软件包? 我是-所以我写了一个简单的bash脚本来处理它。

Read on for a quick tutorial or check out the Github repo containing the script and CloudFormation template.

请继续阅读以获取快速教程,或查看包含脚本和CloudFormation模板的Github存储库 。

For some reason I don’t understand, Amazon insists on using Python 2 on their standard Amazon Linux 2 EC2 instances. Of course, on a project I’ve recently been working on, I needed Python3. Per usual, virtual environments to the rescue.

由于某些我不理解的原因,Amazon坚持在其标准Amazon Linux 2 EC2实例上使用Python 2。 当然,在我最近正在进行的一个项目中,我需要Python3。 通常,可以通过虚拟环境进行救援。

Normally, I would just install Anaconda and be good-to-go. However, my project also makes heavy use of AWS’s CloudFormation tools to automatically deploy stacks of resources from a template, so I needed a way of automating the install. I also wanted the freshly-minted EC2 instances to have the AWS CLI and Boto3 Python package installed.

通常,我只安装Anaconda即可。 但是,我的项目还大量使用AWS的CloudFormation工具从模板自动部署资源堆栈,因此我需要一种自动化安装的方法。 我还希望刚创建的EC2实例安装AWS CLI和Boto3 Python软件包。

Fortunately, AWS provides a ‘UserData’ key when provisioning EC2 instances that can run user defined bash commands and run shell scripts.

幸运的是,在配置可运行用户定义的bash命令和运行Shell脚本的EC2实例时,AWS提供了“ UserData”键。

As often is the case, something that I thought would be simple ended up taking up several hours, but hopefully this script will help save you the same headache. Here’s a quick tutorial on how to use the script and template, which you can get at this link:

通常情况下,我认为很简单的事情最终要花费几个小时,但是希望该脚本可以帮助您避免同样的头痛。 这是有关如何使用脚本和模板的快速教程,您可以在以下链接中获得:

** Github Repo Link Here **

** Github Repo链接在这里**

步骤1:在AWS控制台中打开CloudFormation模板 (Step 1: Open the CloudFormation Template in the AWS Console)

Get the template file from the repo link above, and open it in the CloudFormation designer.

从上面的repo链接获取模板文件,然后在CloudFormation设计器中将其打开。

Click ‘create stack’ in the upper left corner, and input the necessary parameters (your AWS API key/secret, SSH Key Name, etc.)

单击左上角的“创建堆栈”,然后输入必要的参数(您的AWS API密钥/秘密,SSH密钥名称等)。

Click through the rest of the prompts with ‘next’ and then create the stack. You should get a ‘CREATE_IN_PROGRESS’ message like the one below…

单击带有“ next”的其余提示,然后创建堆栈。 您应该会收到类似以下内容的“ CREATE_IN_PROGRESS”消息……

…And then a ‘CREATE_COMPLETE’ when finished (this can take quite a bit of time — 10 minutes often — Anaconda is quite a hefty install):

…然后在完成时显示“ CREATE_COMPLETE”(这可能会花费很多时间-通常是10分钟-Anaconda的安装量很大):

第2步:SSH进入您的新实例以验证安装 (Step 2: SSH into your new instance to verify the install)

Using your favorite SSH client, log in to your new instance. You should be able to quickly check that Anaconda successfully installed by typing:

使用您喜欢的SSH客户端,登录到新实例。 您应该能够通过键入以下内容快速检查Anaconda是否已成功安装:

conda activate python3

Verify that the prompt on the SSH client changes to show the ‘python3’ activate being active. Also, you can verify that the AWS CLI properly installed by typing:

验证SSH客户端上的提示是否更改为显示“ python3”激活处于活动状态。 此外,您可以通过键入以下命令验证是否正确安装了AWS CLI:

cd ~/.awsls

You should see the ‘credentials’ file created in that directory.

您应该看到在该目录中创建的“凭据”文件。

If you meet the above checks, you should be done. Good luck with the rest of your project!

如果满足以上检查条件,则应该完成。 祝您在项目的其余部分中一切顺利!

翻译自: https://www.freecodecamp.org/news/how-to-automate-installation-of-anaconda-on-aws-ec2-instances-e9db8aa0570d/

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/7327.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息