slack通知本地服务器_通过构建自己的Slack App学习无服务器

本文介绍了无服务器架构的概念及其优势,包括成本效益和易扩展性。通过逐步指导设置AWS Lambda、创建无服务器应用程序以及构建Slack应用,读者将学会如何利用Serverless架构创建一个能发送提醒的Slack应用。文章还涵盖了添加API、连接代码与Slack应用以及设置斜线命令的过程。
摘要由CSDN通过智能技术生成

slack通知本地服务器

Serverless architecture is the industry's latest buzzword and many of the largest tech companies have begun to embrace it.

无服务器架构是业界最新的流行语,许多大型科技公司已开始采用它。

In this article, we'll learn what it is and why you should use it. We'll also set up AWS, create our serverless app, and create a slack app!

在本文中,我们将学习它的含义以及为什么要使用它。 我们还将设置AWS,创建无服务器应用程序,并创建一个松弛应用程序!

什么是无服务器? (What is Serverless?)

Serverless is a cloud computing paradigm in which the developer no longer has to worry about maintaining a server – they just focus on the code.

无服务器是一种云计算范例,开发人员无需在其中维护服务器,而只需关注代码。

Cloud providers, such as AWS or Azure, are now responsible for executing code and maintaining servers by dynamically allocating their resources. A variety of events can trigger code execution, including cron jobs, http requests, or database events.

现在,AWS或Azure之类的云提供商负责通过动态分配资源来执行代码和维护服务器。 各种事件可以触发代码执行,包括cron作业,http请求或数据库事件。

The code that developers send to the cloud is usually just a function so, many times, serverless architecture is implemented using Functions-as-a-Service, or FaaS. The major cloud providers provide frameworks for FaaS, such as AWS Lambda and Azure Functions.

开发人员发送到云的代码通常只是一个功能,因此很多时候,无服务器架构是使用“功能即服务”或FaaS实现的。 主要的云提供商提供了适用于FaaS的框架,例如AWS Lambda和Azure Functions。

为什么没有服务器? (Why Serverless?)

Not only does serverless allow developers to just focus on code, but it has many other benefits as well.

无服务器不仅使开发人员可以专注于代码,而且还具有许多其他好处。

Since cloud providers are now responsible for executing code and dynamically allocate resources based on event triggers, you typically only pay per request, or when your code is being executed.

由于云提供商现在负责执行代码并根据事件触发器动态分配资源,因此您通常只按请求付费或执行代码时付费。

Additionally, since cloud providers are handling your servers, you don't have to worry about scaling up – the cloud provider will handle it. This makes serverless apps lower cost, easier to maintain, and easier to scale.

此外,由于云提供商正在处理您的服务器,因此您不必担心扩展问题–云提供商将处理它。 这使无服务器应用程序成本更低,更易于维护且更易于扩展。



设置AWS Lambda (Setting up AWS Lambda)

For this tutorial, I will be using AWS Lambda, so first, we'll create an AWS account. I find AWS's UI hard to understand and difficult to navigate, so I will be adding screenshots for each step.

在本教程中,我将使用AWS Lambda,因此,首先,我们将创建一个AWS账户 。 我发现AWS的UI难以理解且难以导航,因此我将为每个步骤添加屏幕截图。

Once you log in, you should see this:

登录后,您应该会看到以下内容:

Next, we'll set up an IAM user. An IAM (Identity and Access Management) user interacts with AWS and its resources on your behalf. This allows you to create different IAM users with different permissions and purposes, without compromising the security of your root user account.

接下来,我们将设置一个IAM用户。 IAM (身份和访问管理)用户代表您与AWS及其资源进行交互。 这使您可以创建具有不同权限和目的的不同IAM用户,而不会损害根用户帐户的安全性。

Click on the "services" tab at the top of the page, and type "IAM" into the bar:

单击页面顶部的“服务”选项卡,然后在栏中输入“ IAM”:

Click on the first result, and you'll see, on the left-hand sidebar, that you're at the dashboard. Click on the "Users" option to get to create our new IAM user.

单击第一个结果,您将在左侧边栏上看到位于仪表板。 单击“用户”选项以创建我们的新IAM用户。

Click on the "Add user" button to create a new user. Fill in the details as follows:

单击“添加用户”按钮创建一个新用户。 填写以下详细信息:

You can name your user anything you'd like, but I went with serverless-admin. Be sure that your user has "Programmatic access" to AWS, not "AWS Management Console Access". You'd use the latter for teammates, or other humans who need access to AWS. We just need this user to interact with AWS Lambda, so we can just give them programmatic access.

您可以根据需要命名用户,但是我使用serverless-admin 。 确保您的用户具有对AWS的“程序访问”, 而不是 “ AWS管理控制台访问”。 你会使用后者对谁需要访问AWS的队友,或者其他 。 我们只需要该用户与AWS Lambda进行交互,因此我们可以为他们提供编程访问权限。

For permissions, I've chosen to attach existing policies since I don't have any groups, and I don't have any existing users that I want to copy permissions for. In this example, I will create the user with Administrator access since it's just for a personal project; however, if you were to use a serverless app in an actual production environment, your IAM user should be scoped to only access Lambda-necessary parts of AWS. (Instructions can be found here).

对于权限,由于没有任何组,并且没有要复制其权限的现有用户,因此我选择附加现有策略。 在此示例中,我将创建具有管理员访问权限的用户,因为它仅用于个人项目。 但是,如果要在实际生产环境中使用无服务器应用程序,则应将IAM用户的范围限定为仅访问AWS的Lambda必需部分。 (说明可在此处找到)。

I didn't add any tags and created the user. It's vital to save the information given to you on the next screen - the Access ID and Secret Access Key.

我没有添加任何标签并创建了用户。 将提供给您的信息保存在下一个屏幕上至关重要-访问ID和秘密访问密钥。

Don't leave this screen without copying down both! You won't be able to see the Secret access key again after this screen.

不要在不抄袭两者的情况下离开此屏幕! 在此屏幕之后,您将无法再次看到“秘密”访问密钥。

Finally, we'll add these credentials to command line AWS. Use this guide to get aws cli setup.

最后,我们将这些凭证添加到命令行AWS。 使用本指南获取AWS CLI设置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值