aws fargate_我如何在AWS Fargate上部署#100DaysOfCloud Twitter Bot
aws fargate
After passing my last certification, I asked myself how much time I spent studying cloud computing.
通过上一份认证后,我问自己自己花了多少时间研究云计算。
More than 100 days!
超过100天!
It also made me realize two things:
这也让我意识到两件事:
- There was no #100DaysOfCloud challenge没有#100DaysOfCloud挑战
- We have now enough content to create this challenge现在,我们有足够的内容来应对这一挑战
So I immediately contacted Alex Kallaway, the creator of #100DaysOfCode, to ask him if it was possible to create #100DaysOfCloud based on his challenge.
因此,我立即联系#100DaysOfCode的创建者Alex Kallaway,询问他是否有可能根据他的挑战创建#100DaysOfCloud。
And a few days later, the #100DaysOfCloud challenge was official:
几天后,#100DaysOfCloud挑战赛正式开始:
But something was missing.
但是缺少了一些东西。
If you already used the #100DaysOfCode hashtag, you know that your tweets are going to be retweeted at least three times by Twitter bots.
如果您已经使用#100DaysOfCode主题标签,则知道Twitter机器人将至少转发3次您的推文。
Because there were no bots for the new #100DaysOfCloud challenge, I decided to fix that problem.
因为没有新的#100DaysOfCloud挑战机器人,所以我决定解决此问题。
In this post, we're gonna see how I deployed my Twitter bot and why I choose to deploy it on AWS Fargate.
在本文中,我们将看到我如何部署Twitter机器人以及为什么选择在AWS Fargate上部署它。
Let's start!
开始吧!
先决条件 (Prerequisites)
If you want to follow along and run the commands below, be sure to:
如果要继续并运行以下命令,请确保:
Have an AWS account with access key and secret key
拥有一个具有访问密钥和秘密密钥的AWS账户
Have Twitter API Authentication Credentials
拥有Twitter API身份验证凭据
Install Docker on your machine
在您的机器上安装Docker
Clone the repository from https://github.com/johanrin/100-days-of-cloud-bot
从https://github.com/johanrin/100-days-of-cloud-bot克隆存储库
为什么选择AWS Fargate? (Why AWS Fargate?)
If you check my code, you’ll see that:
如果检查我的代码,您会看到:
- The code is written in Python and use tweepy package该代码是用Python编写的,并使用tweepy包
The bot is always running (using a
while
loop)机器人始终处于运行状态(使用
while
循环)There is a
Dockerfile
to build my image有一个
Dockerfile
构建我的映像
I will not explain all the code because that's beyond the scope of this post. But I did mention all the sources I used in the GitHub repository.
我不会解释所有代码,因为这超出了本文的范围。 但是我确实提到了我在GitHub存储库中使用的所有资源。
My idea was to deploy the Docker image in a container in the cloud with the following constraints:
我的想法是将Docker映像部署在云中的容器中,并具有以下限制:
- I don't want to spend much money我不想花很多钱
- I don't want to manage and operate servers我不想管理和操作服务器
Because I have credits on AWS, the first constraint was easy — go with AWS.
因为我对AWS有信誉,所以第一个约束很容易-选择AWS。
As for constraint number 2, I knew from the AWS Certified Developer - Associate course, that we could deploy serverless containers with AWS Fargate.
关于约束2,我从AWS Certified Developer-Associate课程知道,我们可以使用AWS Fargate部署无服务器容器。
Depending on your region, the pricing for AWS services can vary. It's often just a matter of a few cents, but I planned to run my bot for at least one year. So, every cent mattered.
根据您所在的地区,AWS服务的价格可能有所不同。 通常只需几美分,但我计划将我的机器人运行至少一年。 因此,每一分都很重要。
To see AWS Fargate pricing and minimize your cost, you can check the AWS documentation. I found that the cheapest region close to me was Ireland, so I decided to deploy my bot to AWS Fargate there.
要查看AWS Fargate定价并最大程度地降低成本,您可以查看AWS文档 。 我发现距离我最近的最便宜的地区是爱尔兰,因此我决定将我的机器人部署到那里的AWS Fargate。
我如何部署我的机器人? (How did I deploy my bot?)
Now that I've explained why I used AWS Fargate, let's see how I deployed my bot.
现在,我已经解释了为什么使用AWS Fargate的原因,让我们看看如何部署我的机器人。
There are two big steps to deploy a Docker image on AWS Fargate:
在AWS Fargate上部署Docker映像有两个重要步骤:
- Push the Docker image to Amazon Elastic Container Registry (ECR)将Docker映像推送到Amazon Elastic Container Registry(ECR)
- Deploy the Docker image on Fargate在Fargate上部署Docker映像
Let's explain each step in detail.
让我们详细解释每个步骤。
将Docker映像推送到Amazon Elastic Container Registry(ECR) (Push the Docker image to Amazon Elastic Container Registry (ECR))
In the root directory, build your image from the
Dockerfile
.在根目录中,从
Dockerfile
构建映像。
docker build . -t 100-days-of-cloud-bot
- Authenticate your Docker to Amazon ECR.对您的Docker进行Amazon ECR身份验证。
aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
- Tag your image with the Amazon ECR repository.用Amazon ECR存储库标记图像。
docker tag 100-days-of-cloud-bot aws_account_id.dkr.ecr.region.amazonaws.com/100-days-of-cloud-bot
- Push your image to Amazon ECR.将您的图像推送到Amazon ECR。
docker push aws_account_id.dkr.ecr.region.amazonaws.com/100-days-of-cloud-bot
在Amazon Fargate上部署Docker映像 (Deploy the Docker image on Amazon Fargate)
Open the Amazon ECS console first run wizard.
打开Amazon ECS控制台首次运行向导 。
Click Configure in the custom container, complete with the following settings, and then select Update.
单击自定义容器中的“ 配置 ”,完成以下设置,然后选择“ 更新” 。
Property | Value |
---|---|
Container name | container-100-days-of-cloud-bot |
Image | aws_account_id.dkr.ecr.region.amazonaws.com/100-days-of-cloud-bot |
Memory Limits (MiB) | Soft Soft limit | 512 |
Port mappings | Container port: 80Protocol: tcp |
CPU units | 256 |
Environment variables (Twitter API Authentication Credentials) | CONSUMER_KEY | Value | consumer_key CONSUMER_SECRET | Value | consumer_secret ACCESS_TOKEN | Value | access_token ACCESS_TOKEN_SECRET | Value | access_token_secret |
属性 | 值 |
---|---|
容器名称 | 容器-100天的云机器人 |
图片 | aws_account_id.dkr.ecr.region.amazonaws.com/100天云漫游器 |
内存限制(MiB) | 软限制 512 |
端口映射 | 货柜码头 :80 通讯协议 :tcp |
CPU单元 | 256 |
环境变量 (Twitter API身份验证凭据) | CONSUMER_KEY | 价值| Consumer_key CONSUMER_SECRET | 价值| Consumer_secret ACCESS_TOKEN | 价值| access_token ACCESS_TOKEN_SECRET | 价值| access_token_secret |
Click Edit in the Task definition section, complete with the following settings, and then select Save.
单击“ 任务定义”部分中的“ 编辑 ”,完成以下设置,然后选择“ 保存” 。
Property | Value |
---|---|
Task definition name | task-definition-100-days-of-cloud-bot |
Task memory | 0.5GB (512) |
Task CPU | 0.25 vCPU (256) |
属性 | 值 |
---|---|
任务定义名称 | 任务定义100天云机器人 |
任务记忆 | 0.5GB(512) |
任务CPU | 0.25 vCPU(256) |
Click Next.
单击下一步 。
Click Edit in the Define your service section, complete with the following settings, and then select Save.
点击定义您的服务部分中的编辑 ,完成以下设置,然后选择保存 。
Property | Value |
---|---|
Service name | service-100-days-of-cloud-bot |
Number of desired tasks | 1 |
Load balancer type | None |
属性 | 值 |
---|---|
服务名称 | 服务100天的云机器人 |
所需任务数 | 1个 |
负载均衡器类型 | 没有 |
We don't need a load balancer here because of the Twitter API rate limit. Even if we scale-out our containers, Twitter's API will send us a 420 error message because the bot is being rate limited for making too many requests.
由于Twitter API速率限制,我们在这里不需要负载均衡器。 即使我们向外扩展容器,Twitter的API也会向我们发送420错误消息,因为该漫游器由于发出过多请求而受到速率限制。
Click Next.
单击下一步 。
Edit your Cluster name with cluster-100-days-of-cloud-bot.
使用cluster-100-days-cloud-bot编辑您的集群名称 。
Click Next.
单击下一步 。
Review your configuration and click Create.
查看您的配置,然后单击创建 。
That's it, the container is deployed on AWS Fargate!
就是这样,容器已部署在AWS Fargate上!
结论 (Conclusion)
You deployed your Twitter bot on AWS Fargate with only four steps. 🎉🎉🎉
您只需四个步骤就可以将Twitter机器人部署到AWS Fargate上。 🎉🎉🎉
AWS Fargate is easy to use, allowing us to deploy containers without managing and operating servers.
AWS Fargate易于使用,使我们无需管理和操作服务器即可部署容器。
This use case was simple, but we can do much more like adding a load balancer or defining more tasks. I recommend you to check the documentation for more details.
这个用例很简单,但是我们可以做更多的事情,例如添加负载平衡器或定义更多任务。 我建议您检查文档以了解更多详细信息。
Because this post was about the #100DaysOfCloud challenge, I should mention that we have Discord server, so feel free to join the community and the challenge! We have amazing people from all around the world ready to help you to get started with the Cloud.
因为这篇文章是关于#100DaysOfCloud挑战的,所以我应该提到我们有Discord服务器 ,所以随时加入社区和挑战吧! 我们有来自世界各地的出色人才,随时可以帮助您开始使用Cloud。
That’s it for me, hope you learned something!
对我来说就是这样,希望您能学到一些东西!
翻译自: https://www.freecodecamp.org/news/how-i-deployed-my-100daysofcloud-twitter-bot-on-aws-fargate/
aws fargate
相关文章:

think in Java 第五章之垃圾回收类型
1.引用计数: 每个对象都含有一个引用计数器,当有引用连接至对象时,引用计数加1,当引用离开作用域或被置为null时,引用计数减1. 缺陷:在对象循环引用时,存在“对象应该被回收,引用计数…
Yii 错误页面处理
【错误页面处理】 訪问一个错误的控制器 訪问一个错误的方法 有些控制器和方法禁止訪问 以上訪问会提示错误信息 404 403 以上错误信息是不方便给外边用户看到的。 1. 安全隐患 2. 用户体验不好 错误信息在site/error这个地方定义的。如今我们要自己定义错误页面来显示我们的错…

设置RGBColor
#define kUIColorFromRGB(rgbValue) [UIColor \colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

自学成才翁_作为一名自学成才的开发者从“我的旅程”中吸取的教训
自学成才翁The path of the self-taught developer is tough and filled with uncertainty. There is no straight line from newbie to career programmer. Because of this, I believe all self-taught developers have a unique story to tell.自学成才的开发者之路艰难而充…

67)vector的begin() end() 和 front() back()的区别 rbegin() rend()
1) 2)v1.begin() 和v1.end() 是作为迭代器v1的 第一个位置 和 最后一个元素的下一个位置。 v1.front() 是v1这个动态数组的第一个元素的值 v1.back()是v1的最后一个元素的值。 3) 4)正向和反向的使…

倒置函数reverse的用法
倒置字符串函数reverse:用于倒置字符串s中的各个字符的位置,如原来字符串中如果初始值为123456,则通过reverse函数可将其倒置为654321,程序如下:#include<stdio.h>#include<string.h>void reverse(char s[…

设置tabbaritem的title的颜色及按钮图片
设置title颜色: [[UITabBarItem appearance] setTitleTextAttributes:{NSForegroundColorAttributeName : kUIColorFromRGB(0xb2151c)} forState:UIControlStateSelected]; 设置按钮图片: UIImage *commonImage [UIImage imageNamed:[NSString strin…
helm部署仓库中没有的包_Kubernetes的Helm软件包管理器简介
helm部署仓库中没有的包Before we dive into the Helm package manager, Im going to explain some key concepts to deploying any application anywhere. Ill also give you a brief introduction to Kubernetes terminology.在深入研究Helm软件包管理器之前 ,我将…

mem 族函数的实现
1.void * memcpy ( void * dest, const void * src, size_t num ); 头文件:#include <string.h>memcpy() 用来复制内存,memcpy() 会复制 src 所指的内存内容的前 num 个字节到 dest 所指的内存地址上。memcpy() 并不关心被复制的数据类型ÿ…

快排递归非递归python_Python递归神经网络终极指南
快排递归非递归pythonRecurrent neural networks are deep learning models that are typically used to solve time series problems. They are used in self-driving cars, high-frequency trading algorithms, and other real-world applications.循环神经网络是深度学习模型…

我的hadoop学习之路
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上。 Hadoop的框架最核心的设计就是:HDFS和MapRedu…

日期处理工具类 -【二】
1、返回本周的第一天(周日为每周第一天) 1 /**2 * 返回本周的第一天(周日为每周第一天)3 * return4 */5 public static String getTheFirstDayOfThisWeek(){6 SimpleDateFormat format new SimpleDateFormat("yyyy-MM-dd");7 Calendar cal Calendar.get…

超越对手pdf_如何创建一个超越竞争对手的移动应用
超越对手pdfThe amount of time people spend on their mobile phones has increased over the years, and so has the number of people using mobile devices.多年来,人们在手机上花费的时间增加了,使用移动设备的人数也增加了。 It’s safe to say t…

vue路由对象($route)参数简介
路由对象在使用了 vue-router 的应用中,路由对象会被注入每个组件中,赋值为 this.$route ,并且当路由切换时,路由对象会被更新。 so , 路由对象暴露了以下属性: 1.$route.path 字符串,等于当前路由对象的路…

join......on 后面的and 和where的区别
a.where 是在两个表join完成后,再附上where条件。 b. and 则是在表连接前过滤A表或B表里面哪些记录符合连接条件,同时会兼顾是left join还是right join。即 假如是左连接的话,如果左边表的某条记录不符合连接条件,那么它不…

block的运用
cell的.h文件 typedef void(^ActivityCellBlock)(NSString *str); interface ActivityCell : UITableViewCell property (nonatomic,strong) NSArray *labelAry; property (nonatomic,copy) ActivityCellBlock myBlock; -(void)showCell:(ActivityCellBlock)myBlock; cel…

如何在Ubuntu 20.04上设置Python虚拟环境
I recently got myself a “new” laptop – a Lenovo x270 (yay)! And once again I needed to set up a Python virtual environment. So of course I Googled for a solution, just to find my previously written article on the same topic!我最近给自己买了一台“新”笔记…

getURLParameters - 网址参数
返回包含当前URL参数的对象。 通过适当的正则表达式,使用 String.match() 来获得所有的键值对, Array.reduce() 来映射和组合成一个单一的对象。 将 location.search 作为参数传递给当前 url。 const getURLParameters url >url.match(/([^?&])…

block的使用
#import "ViewController.h" /* 使用Block最大的一个好处就是可以在代码块中随时访问外部变量 比如你在A.class类中的某个方法中声明了一段代码块.你可以在代码块中直接对A.class所拥有的成员变量进行调用,并且,通过一定的条件(__block),还可以随时的修改这…

关于二级菜单的问题
大家在做二级菜单的时候经常会碰到鼠标移出一级菜单,二级菜单瞬间消失,根本不给你机会移到二级菜单上,今天分享下怎样解决这个问题。 ①第一种介绍一种简单粗暴的方法,二级菜单的元素放入一级菜单中。 代码地址:http:h…

python打印换行符_Python换行符以及如何在不使用换行符的情况下进行Python打印
python打印换行符Welcome! The new line character in Python is used to mark the end of a line and the beginning of a new line. Knowing how to use it is essential if you want to print output to the console and work with files.欢迎! Python中的新行字…

tomcat启动后 项目运行缓慢,要几十到几百秒不等 怎么样./startup.sh 运行加快
修改 linux系统中 /usr/local/jdk1.8.0_11/jre/lib/security/java.security 借力 好文章。我们新的Linux系统,部署了多个 Tomca,同时重启后t, 每次都阻塞差不多260秒左右。修改之后总的启动时间下降到6-8秒左右。另外,不确定为什么࿰…

转载 C#中使用结构来传递多个参数
C#中当参数超过5个时,建议用结构来传递多个参数。 示例代码如下: 1 public struct MyStruct2 {3 public string str;4 public int number;5 }6 7 class Program8 {9 static void Main(string[] args) 10 { 11 MyStruct myStruct…

xmpp 开源项目选择_如何选择和维护安全的开源项目
xmpp 开源项目选择评估开源项目安全性的一些技巧。 (A few tricks for assessing the security of an open source project.) There is a rather progressive sect of the software development world called the open source community. 在软件开发领域,有一个相当…

【2018-01-22】HTML-表单及表单元素
<body><!--表单--><form action"" method"post"><!--文本类--><input type"text" value"" placeholder"请输入用户名"/><!--文本框--><input type"password" value"…

取消tableView多余的横线
- (void)setExtraCellLineHidden: (UITableView *)tableView{UIView *view [UIView new];view.backgroundColor [UIColor clearColor];[tableView setTableFooterView:view];}

iOS 自定义UITabBar
推荐一篇非常好的集成各种UITabBar的三方库 《点击这里直取demo》 另外一篇根据runtime定制了一款可以出轨的UITarBar 《Runtime实战之定制TabBarItem大小》 点击view的触发机制《iOS事件分发机制(一) hit-Testing》 摘自: UIView中提供两个…

react入门代码_如何在React中构建温度控制应用程序-包括提示和入门代码
react入门代码我们正在建立的 (What were building) In this beginner React project, were going to learn how to use state hooks, handle events, apply CSS based on state, and more! Check it out: 在这个初学者的React项目中,我们将学习如何使用状态挂钩&am…

决策树(chap3)Machine Learning In Action学习笔记
优点:计算复杂度不高,输出结果易于理解,对中间值的缺失不敏感,可以处理不相关特征数据。缺点:可能会产生过度匹配问题。适用数据类型:数值型(必须离散化)和标称型。决策树创建分支的…

BigdCIMAL类型数据的使用选择
现在常用的数值类型有Integer , Double , Float , BigDecimal几种 , 常用的当然要数前两种 了 , Integer代表的是整数类型的数据 , double则是代表的是浮点型 , 双精度 ,double的计算精度相对于float来讲要 高 , BigDecimal的计算精度则是最高的 . 可是BigDecimal的一些计算方…