slack通知本地服務器_通過構建自己的Slack App學習無服務器

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設置。

Make sure you have it installed by running aws --version. You should see something like this:

通過運行aws --version確保已安裝它。 您應該會看到以下內容:

Then run aws configure and fill in the prompts:

然后運行aws configure并填寫提示:

I have the default region as us-east-2 already set up, but you can use this to determine what your region is.

我已經設置了默認區域,因為us-east-2已經設置好了,但是您可以使用它來確定您所在的區域。

To make sure that you have your credentials set up correctly, you can run cat ~/.aws/credentials in your terminal.

為了確保您正確設置了憑據,可以在終端中運行cat ~/.aws/credentials

If you want to configure a profile other than your default, you can run the command as follows: aws configure --profile [profile name].

如果要配置默認配置文件以外的配置文件,則可以按以下方式運行命令: aws configure --profile [profile name]

If you had trouble following the steps, you can also check out AWS's documentation.

如果您在執行步驟時遇到麻煩,還可以查看AWS文檔 。



設置無服務器 (Set up serverless)

Go to your terminal and install the serverless package globally using npm: npm i -g serverless. (More info on serverless here)and your terminal should look something like this:

轉到終端并使用npm全局安裝serverless軟件包: npm i -g serverless 。 ( 有關無服務器的更多信息,請參見此處 ),您的終端應如下所示:

Next, navigate to the directory where you want to create the app, then run serverless and follow the prompts:

接下來,導航到您要在其中創建應用程序的目錄,然后運行serverless并按照提示進行操作:

For this application, we'll be using Node.js. You can name your app anything you want, but I've called mine exampleSlackApp.

對于此應用程序,我們將使用Node.js。 您可以根據自己的喜好為應用命名,但是我將其命名為exampleSlackApp

Open your favorite code editor to the contents in exampleSlackApp (or whatever you've called your application).

打開您最喜歡的代碼編輯器,查看exampleSlackApp (或您所謂的應用程序)中的內容。

First, we'll take a look at serverless.yml. You'll see there's a lot of commented code here describing the different options you can use in the file. Definitely give it a read, but I've deleted it down to just:

首先,我們來看一下serverless.yml 。 您會在這里看到很多注釋代碼,它們描述了可以在文件中使用的不同選項。 一定要讀一讀,但是我已經將其刪除為:

I've included region since the default is us-east-1 but my aws profile is configured for us-east-2.

由于默認值為us-east-1所以我包括了region ,但是我的aws配置文件配置為us-east-2

Let's deploy what we already have by running serverless deploy in the directory of the app that serverless just created for us. The output should look something like this:

讓我們通過在serverless deploy serverless剛剛為我們創建的應用程序的目錄中運行serverless deploy已有的serverless deploy 。 輸出應如下所示:

And if you run serverless invoke -f hello in your terminal, it'll run the app, and you should see:

并且,如果您在終端中運行serverless invoke -f hello ,它將運行該應用程序,您應該看到:

{"statusCode": 200,"body": "{\n  \"message\": \"Go Serverless v1.0! Your function executed successfully!\",\n  \"input\": {}\n}"
}

For further proof that our slack app is live, you can head back to AWS console. Go to the services dropdown, search for "Lambda", and click on the first option ("Run code without thinking about servers").

為了進一步證明我們的Slack應用程序是在線的,您可以返回AWS控制臺。 轉到服務下拉菜單,搜索“ Lambda”,然后單擊第一個選項(“運行代碼而無需考慮服務器”)。

And here's your app!

這是您的應用!

Next, we'll explore actually using serverless by building our slack app. Our slack app will post a random Ron Swanson quote to slack using a slash command like this:

接下來,我們將通過構建我們的松弛應用程序來探索實際使用無服務器的情況。 我們的Slack應用程序將使用如下斜杠命令將Ron Swanson隨機報價發布到Slack:

The following steps don't necessarily have to be done in the order that I've done them, so if you want to skip around, feel free!

不一定必須按照我做的順序來完成以下步驟,因此,如果您想略過一遍,請放心!



將API添加到我們的代碼中 (Adding the API to our code)

I'm using this API to generate Ron Swanson quotes since the docs are fairly simple (and of course, it's free). To see how requests are make and what gets returned, you can just put this URL in your browser:

我使用此API生成Ron Swanson報價,因為這些文檔非常簡單(當然,它是免費的)。 要查看請求的發出方式和返回的內容,您可以將以下URL放入瀏覽器中:

https://ron-swanson-quotes.herokuapp.com/v2/quotes

https://ron-swanson-quotes.herokuapp.com/v2/quotes

You should see something like this:

您應該會看到以下內容:

So, we can take our initial function and modify it as such:

因此,我們可以采用初始功能并將其修改為:

and getRon looks like:

getRon看起來像:

function getRon() {request('https://ron-swanson-quotes.herokuapp.com/v2/quotes', function (err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)})
}

Now, let's check if it works. To test this code locally, in your terminal: serverless invoke local -f hello. Your output should look something like:

現在,讓我們檢查一下是否可行。 要在本地測試此代碼,請在您的終端中: serverless invoke local -f hello 。 您的輸出應類似于:

serverless invoke -f hello would run the code that you've deployed, as we saw in previous sections. serverless invoke local -f hello, however, runs your local code, so it's useful for testing. Go ahead and deploy using serverless deploy!

如前幾節所述, serverless invoke -f hello將運行您已部署的代碼。 serverless invoke local -f hello ,但是運行本地代碼,因此對于測試非常有用。 繼續并使用serverless deploy



創建您的Slack應用 (Create your Slack App)

To create your slack app, follow this link. It'll make you sign into a slack workspace first, so be sure you're a part of one that you can add this app to. I've created a testing one for my purposes. You'll be prompted with this modal. You can fill in whatever you want, but here's what I have as an example:

要創建您的Slack應用,請點擊以下鏈接 。 這將使您首先登錄到一個松弛的工作區,因此請確保您是可以添加此應用程序的一部分。 我已經為我的目的創建了一個測試。 系統會提示您。 您可以填寫任何內容,但以下是我的示例:

From there, you'll be taken to the homepage for your app. You should definitely explore these pages and the options. For example, I've added the following customization to my app:

從那里,您將被帶到應用程序的主頁。 您絕對應該瀏覽這些頁面和選項。 例如,我已將以下自定義添加到我的應用程序:

Next, we need to add some permissions to the app:

接下來,我們需要為應用添加一些權限:

To get an OAuth Access Token, you have to add some scope and permissions, which you can do by scrolling down:

要獲取OAuth訪問令牌,您必須添加一些范圍和權限,您可以通過向下滾動來做到這一點:

I've added "Modify your public channels" so that the bot could write to a channel, "Send messages as Ron Swanson" so when the message gets posted, it looks like a user called Ron Swanson is posting the message, and slash commands so the user can "request" a quote as shown in the screenshot at the beginning of the article. After you save the changes, you should be able to scroll back up to OAuths & Permissions to see:

我添加了“修改您的公共頻道”,以便該機器人可以將其寫入頻道“以Ron Swanson的身份發送消息”,這樣,當該消息被發布時,它看起來就像一個名叫Ron Swanson的用戶正在發布該消息,并使用斜杠因此用戶可以“請求”報價,如本文開頭的屏幕快照所示。 保存更改后,您應該可以回滾到OAuths和Permissions來查看:

Click the button to Install App to Workspace, and you'll have an OAuth Access Token! We'll come back to this in a second, so either copy it down or remember it's in this spot.

單擊按鈕將應用程序安裝到工作區,您將獲得OAuth訪問令牌! 我們將在稍后再討論,因此請復制下來或記住它在該位置。



連接代碼和Slack應用 (Connect Code and Slack App)

In AWS Lambda, find your slack app function. Your Function Code section should show our updated code with the call to our Ron Swanson API (if it does not, go back to your terminal and run serverless deploy).

在AWS Lambda中,找到您的松弛應用程序功能。 您的功能代碼部分應顯示對我們Ron Swanson API的調用的更新后的代碼(如果沒有,請返回到您的終端并運行serverless deploy )。

Scroll below that to the section that says "Environment Variables", and put your Slack OAuth Access Token here (you can name the key whatever you'd like):

滾動到顯示“ 環境變量 ”的部分,然后在此處放置Slack OAuth訪問令牌(您可以根據需要命名密鑰):

Let's go back to our code and add Slack into our function. At the top of our file, we can declare a const with our new OAuth Token:

讓我們回到我們的代碼并將Slack添加到我們的函數中。 在文件的頂部,我們可以使用新的OAuth令牌聲明const

const SLACK_OAUTH_TOKEN = process.env.OAUTH_TOKEN.

const SLACK_OAUTH_TOKEN = process.env.OAUTH_TOKEN

process.env just grabs our environment variables (additional reading). Next, let's take a look at the Slack API to figure out how to post a message to a channel.

process.env只是獲取我們的環境變量( 其他閱讀資料 )。 接下來,讓我們看一下Slack API,以了解如何將消息發布到頻道。

The two pictures above I've taken from the API are the most relevant to us. So, to make this API request, I'll use request by passing in an object called options:

上面我從API拍攝的兩張圖片與我們最相關。 因此,要發出此API請求,我將通過傳入一個名為options的對象來使用request

let options = {url: 'https://slack.com/api/chat.postMessage',headers: {'Accept': 'application/json',},method: 'POST',form: {token: SLACK_OAUTH_TOKEN,channel: 'general', // hard coding for nowtext: 'I am here',}}

and we can make the request:

我們可以提出要求:

request(options, function(err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)})

Finally, I'll wrap the whole thing in a function:

最后,我將整個內容包裝在一個函數中:

function postRon(quote) {let options = {url: 'https://slack.com/api/chat.postMessage',headers: {'Accept': 'application/json',},method: 'POST',form: {token: SLACK_OAUTH_TOKEN,channel: 'general',text: quote,}}request(options, function(err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)})
}

and we can call it from getRon like this:

我們可以像這樣從getRon調用它:

function getRon() {request('https://ron-swanson-quotes.herokuapp.com/v2/quotes', function (err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)postRon(body.substring(2, body.length - 2)) // here for parsing, remove if you want to see how/why I did it})
}

So our code should all in all look like this:

因此,我們的代碼應該全部如下所示:

'use strict';
let request = require('request');const SLACK_OAUTH_TOKEN = process.env.OAUTH_TOKENmodule.exports.hello = (event) => {getRon();
};function getRon() {request('https://ron-swanson-quotes.herokuapp.com/v2/quotes', function (err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)postRon(body.substring(2, body.length - 2))})
}function postRon(quote) {let options = {url: 'https://slack.com/api/chat.postMessage',headers: {'Accept': 'application/json',},method: 'POST',form: {token: SLACK_OAUTH_TOKEN,channel: 'general',text: quote,}}request(options, function(err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)})
}

Now let's test! Unfortunately, our environment variable in AWS Lambda isn't available to us when we run serverless invoke local -f hello. There are a few ways you can approach this, but for our purposes, you can just replace the value for SLACK_OAUTH_TOKEN with your actual OAuth Token (make sure it's a string). But be sure you switch it back before you push it up to version control!

現在讓我們測試! 不幸的是,當我們運行serverless invoke local -f hello時,我們無法使用AWS Lambda中的環境變量。 有幾種方法可以解決此問題,但是出于我們的目的,您可以將SLACK_OAUTH_TOKEN的值替換為實際的OAuth令牌(確保它是字符串)。 但是在將其推向版本控制之前,請確保將其切換回原來的狀態!

Run serverless invoke local -f hello, and hopefully you should see a message like this in your #general channel:

運行serverless invoke local -f hello ,希望您應該在#general頻道中看到如下消息:

Please note that I put down my channel name as 'general' since it's my test workspace; however, if you're in an actual workspace, you should create a separate channel for testing apps, and put the message there instead while you're testing.

請注意,由于它是我的測試工作區,因此我將頻道名稱記為“一般”。 但是,如果您在實際的工作空間中,則應創建一個單獨的通道來測試應用程序,并在測試時在其中放置消息。

And in your terminal, you should see something like:

在終端中,您應該看到類似以下內容的內容:

If that works, go ahead and deploy it using serverless deploy. If it does not, the best way to debug this is to adjust code and run serverless invoke local -f hello.

如果可行,請繼續使用serverless deploy 。 如果不是,調試此錯誤的最佳方法是調整代碼并運行serverless invoke local -f hello



添加斜線命令 (Adding slash command)

The last and final part is adding a slash command! Go back to your function's home page in AWS Lambda and look for the button that says "Add trigger":

最后也是最后一部分是添加斜杠命令! 返回AWS Lambda中函數的主頁,然后查找顯示“添加觸發器”的按鈕:

Click on the button to get to the "Add trigger" page, and select "API Gateway" from the list:

單擊按鈕進入“添加觸發器”頁面,然后從列表中選擇“ API網關”:

I've filled in the information based on defaults mostly:

我主要根據默認值填寫了信息:

I've also left this API open for use – however, if you're using this in production, ?you should discuss what standard protocol would be with your team. "Add" the API, and you should receive an API endpoint. Hold on to this, because we'll need it for the next step.

我還開放了該API的使用權-但是,如果您在生產中使用此API,則應與您的團隊討論什么標準協議。 “添加” API,您將收到一個API端點。 堅持下去,因為下一步將需要它。

Let's switch back over to our slack app and add a slash command:

讓我們切換回我們的Slack應用程序并添加一個斜杠命令:

Click on "Create New Command" and it should pop up with a new window to create a command. Here's how I filled mine out:

單擊“創建新命令”,它將彈出一個新窗口以創建命令。 這是我填寫我的方法:

You can enter anything you want for "command" and "short description" but for "request URL", you should put your API endpoint.

您可以為“命令”和“簡短描述”輸入任何內容,但對于“請求URL”,則應放置API端點。

Finally, we'll go back to our code to make some final adjustments. If you try to use the slash command, you should receive some kind of error back – this is because slack expects a response and AWS expects you to give a response when the endpoint is hit. So, we'll change our function to allow a callback (for reference):

最后,我們將返回到代碼進行一些最終調整。 如果您嘗試使用slash命令,則應該返回某種錯誤-這是因為slack期望響應,而AWS期望在命中端點時做出響應。 因此,我們將更改函數以允許callback ( 僅供參考 ):

module.exports.hello = (event,context,callback) => {getRon(callback);
};

and then we'll change getRon to do something with the callback:

然后我們將getRon更改為對callback執行一些操作:

function getRon(callback) {request('https://ron-swanson-quotes.herokuapp.com/v2/quotes', function (err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)callback(null, SUCCESS_RESPONSE)postRon(body.substring(2, body.length - 2))})
}

where SUCCESS_RESPONSE is at the top of the file:

其中SUCCESS_RESPONSE位于文件頂部:

const SUCCESS_RESPONSE = {statusCode: 200,body: null
}

You can put the callback here or in postRon – it just depends on what your purposes are with the callback.

您可以在此處或在postRon放置回調-這僅取決于回調的用途。

Our code at this point now looks something like:

現在,我們的代碼如下所示:

'use strict';
let request = require('request');const SLACK_OAUTH_TOKEN = OAUTH_TOKENconst SUCCESS_RESPONSE = {statusCode: 200,body: null
}module.exports.hello = (event,context,callback) => {getRon(callback);
};function getRon(callback) {request('https://ron-swanson-quotes.herokuapp.com/v2/quotes', function (err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)callback(null, SUCCESS_RESPONSE)postRon(body.substring(2, body.length - 2))})
}function postRon(quote) {let options = {url: 'https://slack.com/api/chat.postMessage',headers: {'Accept': 'application/json',},method: 'POST',form: {token: SLACK_OAUTH_TOKEN,channel: 'general',text: quote,}}request(options, function(err, resp, body) {console.log('error:', err)console.log('statusCode:', resp && resp.statusCode)console.log('body', body)})
}

You should be able to use the /ron command in slack now and get a Ron Swanson quote back. If you don't, you can use Cloudwatch logs to see what went wrong:

您現在應該可以在松弛狀態下使用/ron命令,并獲得Ron Swanson的報價。 如果沒有,則可以使用Cloudwatch日志查看出了什么問題:

The way our code works now, we've hardcoded in the channel name. But, what we actually want is for the quote to get posted in the message where you used /ron.

現在,我們的代碼工作方式已在渠道名稱中進行了硬編碼。 但是,我們真正想要的是將報價張貼在您使用/ron的消息中。

So, we can now use the event portion of our function.

因此,我們現在可以使用函數的event部分。

module.exports.hello = (event,context,callback) => {console.log(event)getRon(callback);
};

Use /ron to run the function, and then check your Cloudwatch logs to see what gets logged to the console (you may need to refresh). Check on the most recent logs and you should see something like this:

使用/ron運行該功能,然后檢查您的Cloudwatch日志以查看記錄到控制臺的內容(您可能需要刷新)。 查看最新的日志,您應該看到類似以下內容的信息:

The first item in this list (where it says "resource", "path", etc.) is the event, so if you expand that, you'll see a long list of things, but what we're looking for is 'body' all the way down at the bottom:

該列表中的第一項(其上顯示“資源”,“路徑”等)是事件,因此,如果您擴展它,將會看到一長串的東西,但是我們要尋找的是“身體一直向下到底部:

Body is a string with some relevant information in it, one of them being "channel_id". We can use channel_id (or channel_name) and pass it into the function that creates our slack message. For your convenience, I've already parsed this string: event.body.split("&")[3].split("=")[1] should give you the channel_id. I hardcoded in which entry (3) the channel_id was for simplicity.

主體是一個包含一些相關信息的字符串,其中之一是“ channel_id”。 我們可以使用channel_id(或channel_name)并將其傳遞到創建松弛消息的函數中。 為了方便起見,我已經解析了此字符串: event.body.split("&")[3].split("=")[1]應該會給您channel_id。 為了簡單起見,我對channel_id的哪個條目(3)進行了硬編碼。

Now, we can alter our code to save that string as a variable:

現在,我們可以更改代碼以將該字符串保存為變量:

let channel = 'general' (as our fallback)

let channel = 'general' (作為我們的后備)

module.exports.hello = (event,context,callback) => {console.log(event)channel = event.body.split("&")[3].split("=")[1]console.log(context)getGoat(callback);
};

and in postRon:

并在postRon

Finally, if you use a slack command in any channel in your workspace, you should be able to see a Ron Swanson quote pop up! If not, as I mentioned before, the most common tools I use to debug serverless apps are serverless invoke local -f <function name> and Cloudwatch logs.

最后,如果您在工作空間的任何通道中使用松弛命令,那么您應該能夠看到彈出的Ron Swanson報價! 如前所述,如果沒有,我用來調試無服務器應用程序的最常用工具是serverless invoke local -f <function name>和Cloudwatch日志。



Hopefully you were successfully able to create a functioning Slack application! I've included resources and background reading dispersed throughout the article and I'm happy to answer any questions you may have!

希望您能夠成功創建一個正常運行的Slack應用程序! 我在本文中分散了資源和背景知識,很高興回答您可能遇到的任何問題!

Final Repo with code: https://github.com/lsurasani/ron-swanson-slack-app/

最終回購代碼: https //github.com/lsurasani/ron-swanson-slack-app/

翻譯自: https://www.freecodecamp.org/news/make-a-serverless-slack-app/

slack通知本地服務器

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391142.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391142.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391142.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

深入理解InnoDB(6)—獨立表空間

InnoDB的表空間 表空間可以看做是InnoDB存儲引擎邏輯結構的最高層 &#xff0c;所有的數據都是存放在表空間中。 1. Extent 對于16KB的頁來說&#xff0c;連續的64個頁就是一個區&#xff0c;也就是說一個區默認占用1MB空間大小。 每256個區被劃分成一組,第一組的前3個頁面是…

神經網絡推理_分析神經網絡推理性能的新工具

神經網絡推理Measuring the inference time of a trained deep neural model on different hardware devices is a critical task when making deployment decisions. Should you deploy your inference on 8 Nvidia V100s, on 12 P100s, or perhaps you can use 64 CPU cores?…

Eclipse斷點調試

1.1 Eclipse斷點調試概述Eclipse的斷點調試可以查看程序的執行流程和解決程序中的bug1.2 Eclipse斷點調試常用操作:A:什么是斷點&#xff1a;就是一個標記&#xff0c;從哪里開始。B:如何設置斷點&#xff1a;你想看哪里的程序&#xff0c;你就在那個有效程序的左邊雙擊即可。C…

react部署在node_如何在沒有命令行的情況下在3分鐘內將React + Node應用程序部署到Heroku

react部署在nodeIn this tutorial we will be doing a basic React Node app deploy to Heroku. 在本教程中&#xff0c;我們將進行基本的React Node應用程序部署到Heroku。 There are a lot of tutorials that do this only using the command line, so to change things u…

深入理解InnoDB(7)—系統表空間

系統表空間 可以看到&#xff0c;系統表空間和獨立表空間的前三個頁面&#xff08;頁號分別為0、1、2&#xff0c;類型分別是FSP_HDR、IBUF_BITMAP、INODE&#xff09;的類型是一致的&#xff0c;只是頁號為3&#xff5e;7的頁面是系統表空間特有的 頁號3 SYS: Insert Buffer …

CodeForces - 869B The Eternal Immortality

題意&#xff1a;已知a,b&#xff0c;求的最后一位。 分析&#xff1a; 1、若b-a>5&#xff0c;則尾數一定為0&#xff0c;因為連續5個數的尾數要么同時包括一個5和一個偶數&#xff0c;要么包括一個0。 2、若b-a<5&#xff0c;直接暴力求即可。 #include<cstdio>…

如何在24行JavaScript中實現Redux

90% convention, 10% library. 90&#xff05;的慣例&#xff0c;10&#xff05;的圖書館。 Redux is among the most important JavaScript libraries ever created. Inspired by prior art like Flux and Elm, Redux put JavaScript functional programming on the map by i…

卡方檢驗 原理_什么是卡方檢驗及其工作原理?

卡方檢驗 原理As a data science engineer, it’s imperative that the sample data set which you pick from the data is reliable, clean, and well tested for its usability in machine learning model building.作為數據科學工程師&#xff0c;當務之急是從數據中挑選出的…

Web UI 設計(網頁設計)命名規范

Web UI 設計命名規范 一.網站設計及基本框架結構: 1. Container“container“ 就是將頁面中的所有元素包在一起的部分&#xff0c;這部分還可以命名為: “wrapper“, “wrap“, “page“.2. Header“header” 是網站頁面的頭部區域&#xff0c;一般來講&#xff0c;它包含…

leetcode 1486. 數組異或操作(位運算)

給你兩個整數&#xff0c;n 和 start 。 數組 nums 定義為&#xff1a;nums[i] start 2*i&#xff08;下標從 0 開始&#xff09;且 n nums.length 。 請返回 nums 中所有元素按位異或&#xff08;XOR&#xff09;后得到的結果。 示例 1&#xff1a; 輸入&#xff1a;n …

27個機器學習圖表翻譯_使用機器學習的信息圖表信息組織

27個機器學習圖表翻譯Infographics are crucial for presenting information in a more digestible fashion to the audience. With their usage being expanding to many (if not all) professions like journalism, science, and research, advertisements, business, the re…

在HTML中使用javascript (js高級程序設計)

在HTML中使用javascript 剛開始入門的時候覺得關于應用以及在html中只用javascript很簡單&#xff0c;不需要進行學習。我又開始重溫了一下紅寶書&#xff0c;覺得還是有必要進行學習的。這是一個筆記&#xff01; script 元素插入有多種方式 屬性使用方式async延遲腳本&#x…

大數據新手之路二:安裝Flume

Ubuntu16.04Flume1.8.0 1.下載apache-flume-1.8.0-bin.tar.gz http://flume.apache.org/download.html 2.解壓到/usr/local/flume中 3.設置配置文件/etc/profile文件&#xff0c;增加flume的路徑 ①vi /etc/profile export FLUME_HOME/usr/local/flume export PATH$PATH:$FLUME…

leetcode 1723. 完成所有工作的最短時間(二分+剪枝+回溯)

給你一個整數數組 jobs &#xff0c;其中 jobs[i] 是完成第 i 項工作要花費的時間。 請你將這些工作分配給 k 位工人。所有工作都應該分配給工人&#xff0c;且每項工作只能分配給一位工人。工人的 工作時間 是完成分配給他們的所有工作花費時間的總和。請你設計一套最佳的工作…

異步解耦_如何使用異步生成器解耦業務邏輯

異步解耦Async generators are new in JavaScript. They are a remarkable extension. They provide a simple but very powerful tool for splitting programs into smaller parts, making sources easier to write, read, maintain and test.異步生成器是JavaScript中的新增功…

函數的定義,語法,二維數組,幾個練習題

1、請將’A’,’B’,’C’存入數組&#xff0c;然后再輸出2、請將”我” “愛” “你”存入數組&#xff0c;然后正著和反著輸出3、輸入10個整數存入數組&#xff0c;然后復制到b數組中輸出4、定義一個長度為10的數組&#xff0c;循環輸入10個整數。 然后將輸入一個整數&#x…

leetcode 1482. 制作 m 束花所需的最少天數(二分查找)

給你一個整數數組 bloomDay&#xff0c;以及兩個整數 m 和 k 。 現需要制作 m 束花。制作花束時&#xff0c;需要使用花園中 相鄰的 k 朵花 。 花園中有 n 朵花&#xff0c;第 i 朵花會在 bloomDay[i] 時盛開&#xff0c;恰好 可以用于 一束 花中。 請你返回從花園中摘 m 束…

算法訓練營 重編碼_編碼訓練營手冊:沉浸式工程程序介紹

算法訓練營 重編碼Before you spend thousands of dollars and several months of your life on a coding bootcamp, spend 30 minutes reading this handbook.在花費數千美元和一生中的幾個月時間參加編碼訓練營之前&#xff0c;請花30分鐘閱讀本手冊。 這本手冊適用于誰&…

面向Tableau開發人員的Python簡要介紹(第4部分)

用PYTHON探索數據 (EXPLORING DATA WITH PYTHON) Between data blends, joins, and wrestling with the resulting levels of detail in Tableau, managing relationships between data can be tricky.在數據混合&#xff0c;聯接以及在Tableau中產生的詳細程度之間進行搏斗之間…

bzoj 4552: [Tjoi2016Heoi2016]排序

Description 在2016年&#xff0c;佳媛姐姐喜歡上了數字序列。因而他經常研究關于序列的一些奇奇怪怪的問題&#xff0c;現在他在研究一個難題&#xff0c;需要你來幫助他。這個難題是這樣子的&#xff1a;給出一個1到n的全排列&#xff0c;現在對這個全排列序列進行m次局部排序…