七牛服务器入门教程

by Dmitri Zimine

由Dmitri Zimine

使用无服务器,StepFunction和StackStorm Exchange构建社区注册应用 (Building a community sign-up app with Serverless, StepFunctions, and StackStorm Exchange)

Build a real-world serverless application on AWS with Serverless framework and ready-to-use functions from StackStorm Exchange open-source catalog.

使用无服务器框架和StackStorm Exchange开源目录中的即用型功能,在AWS上构建真实的无服务器应用程序。

Episode One | Episode Two | Episode Three | Episode Four

第一集| 第二集 | 第三集 | 第四集

Read on if you are:

如果您是,请继续阅读:

  • A serverless developer using Serverless framework who wants to check out ready-to use functions from the StackStorm Exchange open-source catalog,

    一位使用无服务器框架的无服务器开发人员,他希望从StackStorm Exchange开源目录中检出可立即使用的功能,

  • A StackStorm user who lives in AWS and misses the breadth of StackStorm Exchange integrations there.

    居住在AWS中的StackStorm用户,却错过了那里的StackStorm Exchange集成的广度。

  • Anyone who has 2 hours to follow-along and learn serverless with something more elaborate and real-life than a Hello-world example.

    任何有2个小时的跟踪学习和无服务器学习经验的人,都比Hello-world示例更精致,更真实。

If you only got 8 minutes to spare, skim the text and examples, spend an extra 30 seconds browsing StackStorm Exchange to see the potential, and bookmark this post to get back to it when you need it.

如果您仅剩下8分钟的时间,请浏览文本和示例,花30秒钟额外的时间浏览StackStorm Exchange以查看潜力,并为该帖子添加书签以在需要时返回它。

介绍 (Intro)

When I explored Serverless with Python, StepFunctions, and Web Front-end, one thing I missed is a catalog of reusable integrations. Something like 200 connectors for Azure Logic apps. Or 130 integration packs for StackStorm.

当我使用Python,StepFunctions和Web Front-end探索Serverless时 ,我错过的一件事是可重用集成的目录。 类似于200个用于Azure Logic应用程序的连接器 。 或130个用于StackStorm的集成包 。

When we need to wire in Slack, Jira, Stripe, or Nest, could we skip digging into their APIs and authentication intrinsics, and just grab a ready-to-use function?

当我们需要连接Slack,Jira,Stripe或Nest时,是否可以跳过对它们的API和身份验证内在函数的了解,而只是获取一个现成的功能?

Now we can do exactly that: StackStorm just announced a plugin for Serverless framework that turns integrations from StackStorm Exchange into AWS Lambda functions.

现在我们可以完全做到这一点:StackStorm刚刚宣布了一个用于无服务器框架的插件,该插件可以将StackStorm Exchange的集成转换为AWS Lambda函数。

In this tutorial, I’ll show how to use the plugin and Exchange integrations, in the context of building a serverless community on-boarding application from a ground-up. Let’s make this conversational and fun.

在本教程中,我将展示如何从头开始构建无服务器社区入门应用程序,以及如何使用插件和Exchange集成。 让我们变得有趣而有趣。

I assume no familiarity with either Serverless framework nor StackStorm. But you should know how to code, and be smart to compensate for mistakes and omissions I’ll inevitably make.

我假设对Serverless框架或StackStorm都不熟悉。 但是您应该知道如何编码,并且要聪明地弥补我不可避免的错误和遗漏。

We will be going slow, with excruciating details, thus it is going to be four episodes.

我们将走得很慢,细节令人毛骨悚然,因此将是四集。

In this first episode, I’ll set everything up and deploy my first StackStorm Exchange action.

在第一集中,我将设置所有内容并部署我的第一个StackStorm Exchange操作。

In the next episode, we’ll add more actions.

在下一集中,我们将添加更多操作。

In the third episode I’ll wire them together with a AWS StepFunction.

在第三集中,我将它们与AWS StepFunction连接在一起。

In the fourth episode we’ll add Web Front-end with the Reflection and Summary. Each episode will take about an hour to follow.

在第四集中,我们将在Web前端添加反射和摘要。 每个情节大约需要一个小时。

Ready? Let’s rock.

准备? 开始狂欢吧。

应用程序 (The application)

We will build a community on-boarding application. Actually, rebuilding from scratch the one we run at StackStorm. It’s like SlackIn with a multi-step customizable on-boarding workflow. The app presents a registration web-form, which passes new user info through API Gateway to the StepFunction workflow that carries on-boarding steps.

我们将构建一个社区入门应用程序。 实际上,从头开始重建我们在StackStorm上运行的那个。 就像SlackIn一样, 它具有多步可定制的入职工作流程。 该应用程序显示一个注册网络表单,该表单通过API网关将新的用户信息传递给执行注册步骤的StepFunction工作流程。

In my case, the steps are 1) invite users to Slack 2) create contact record in ActiveCampaign CRM tool and 3) put a user record into internal DynamoDB table. Here is how it looks:

在我的情况下,步骤是1)邀请用户使用Slack; 2)在ActiveCampaign CRM工具中创建联系人记录;以及3)将用户记录放入内部DynamoDB表中。 外观如下:

You can find the previous implementation on github, or use it and join StackStorm community on Slack for questions about StackStorm Exchange integration.

您可以在github上找到以前的实现,或者使用它并在Slack上加入StackStorm社区 ,以获取有关StackStorm Exchange集成的问题。

准备好 (Getting Ready)

First, you’ll need AWS account, NodeJS, Docker, and Serverless framework. And Slack! As our first action will be inviting users to Slack.

首先,您需要AWS帐户,NodeJS,Docker和无服务器框架。 和松弛! 作为第一步,我们将邀请用户使用Slack。

  1. Make sure Node.JS is installed, and it’s version is 8.4.0 or higher.

    确保已安装Node.JS ,并且其版本为8.4.0或更高版本。

  2. Install Serverless framework, and setup AWS credentials for it following this guide.

    安装无服务器框架 ,并按照本指南为其设置AWS凭证。

  3. Install Docker. The plugin uses it for build environment to make the lambdas binary compatible to AWS execution environment no matter what OS you’re using for development. There is a way to make it work without Docker but don’t take chances.

    安装Docker 。 该插件将其用于构建环境,以使lambdas二进制文件与AWS执行环境兼容,无论您使用哪种OS进行开发。 有一种方法可以使它在没有Docker的情况下工作,但不要冒险。

  4. Slack! Our action will require admin access and will be using undocumented Slack API (docs here, pun intended) to invite new users. The easiest is to just go ahead create a new team. Takes 4 min. Slack won’t mind — they’ll show growth to their VC.

    松弛! 我们的操作将需要管理员访问权限,并将使用未记录的Slack API(此处为双关语)来邀请新用户。 最简单的方法就是继续建立新的团队 。 需要4分钟。 Slack不在乎-他们将向VC显示增长。

  5. Once the workspace is created, time to get an authentication token. Go to api.slack.com/custom-integrations/legacy-tokens. Fear not the “Legacy Warnings”: this tutorial will turn legacy before they do. Do what they say, get your token.

    一旦创建了工作空间,就该获取身份验证令牌了。 前往api.slack.com/custom-integrations/legacy-tokens 。 不要害怕“遗留警告”:本教程将先解决遗留问题。 照他们说的做,拿到你的令牌。

PRO TIP: Use this quick hack to get and use your own user’s auth token. Much faster, good for playing and debugging. But please never, never use it for production!

专业提示:使用此快速技巧来获取和使用您自己用户的身份验证令牌。 快得多,适合播放和调试。 但是请永远不要将其用于生产!

创建一个项目,添加第一个动作 (Create a project, add a first action)

Try sls --help to make sure that at least something works. sls is a shorthand for serverless, the Serverless framework CLI. Now put your coffee aside, time to create a project. Some folks like using templates that come with serverless: sls create --template. I prefer to start from scratch:

尝试使用sls --help来确保至少可以正常工作。 slsserverless (无服务器框架CLI)的简写。 现在,将咖啡放在一边,时间来创建一个项目。 一些人喜欢使用无服务器附带的模板: sls create --template 。 我更喜欢从头开始:

mkdir slack-signup-serverless-stormlesscd slack-signup-serverless-stormless
npm init
# Once you answer questions, the project is set up.

Next, install serverless-plugin-stackstorm, the one that plugs in the StackStorm Exchange actions.

接下来,安装serverless-plugin-stackstorm ,它可以插入StackStorm Exchange操作。

npm install --save-dev serverless-plugin-stackstorm

… and create a minimal serverless.ym file so that sls command will pick up the plugin:

…并创建一个最小的serverless.ym文件,以便sls命令选择该插件:

Now, create the first action. I’ll use a battle-tested Slack pack from StackStorm Exchange. Which action, you say? Ok, StackStorm Exchange is not smart enough yet to show pack’s action list, but sls stackstorm will rescue us.

现在, 创建第一个动作 。 我将使用来自StackStorm Exchange的经过战斗测试的Slack软件包 。 您说哪个动作? 好的,StackStorm Exchange还不够智能,无法显示pack的操作列表,但是sls stackstorm可以拯救我们。

sls stackstorm info --pack slack

sls stackstorm info --pack slack

Oh my! There’re so many! what are they? I guess I need a PR to print action description. Meantime, | grep admin will get us the one we need: slack.users.admin.invite. Let's query the action for it's parameters:

天啊! 有很多! 这些是什么? 我想我需要PR才能打印动作说明。 同时, | grep admin | grep admin将为我们提供所需的文件: slack.users.admin.invite 。 让我们查询动作的参数:

$ sls stackstorm info --action slack.users.admin.inviteslack.users.admin.invite ...... Send an invitation to join a Slack OrgParameters  attempts [integer]  ......... description is missing  channels [string]  .......... Channels to auto join.  email [string] (required) ... Email address to send invitation to.  first_name [string]  ........ Users first name  set_active [boolean]  ....... Should the user be active.  token [string]  ............. Slack API token.Config  action_token [string]  ...... Slack Action token.  admin [object]  ............. Admin-action specific settings.  post_message_action [object]   Post message action specific settings.  sensor [object]  ............ Sensor specific settings.

Awesome! We can see that there is only one required parameter, email, but I'll add first_name to stay conversational. The token can be passed as parameters, or as config. And if I choose to use config, my prior tribal knowledge hints that the admin [object] requires only admin_token. The very one I asked you to remember when you were setting up Slack workspace.

太棒了! 我们可以看到只有一个必需的参数email ,但是我将添加first_name来保持对话状态。 令牌可以作为参数或配置传递。 而且,如果我选择使用config,则我先前的部落知识表明admin [object]仅需要admin_token 。 我要您记住设置Slack工作区时的那个。

PRO TIP: While we are still polishing the plugin to expose all the Config details, you can find it out by exploring StackStorm Exchange pack config schema in config.schema.yaml file. For example, here is config.example.yaml for our Slack pack.

专业提示:在我们仍在完善插件以公开所有Config详细信息的同时,您可以通过探索config.schema.yaml文件中的StackStorm Exchange包配置架构来找到它。 例如,这是我们的Slack包的config.example.yaml 。

Now we have all we need to create the heart of any Serverless project: the serverless.yml. Here it comes:

现在,我们拥有创建任何无服务器项目的核心所需的全部内容: serverless.yml 。 它来了:

This is a good time to learn a bit of Serverless. Take a quick break to skim Core Concepts and bookmark Serverless.yml Reference.

这是学习一点无服务器的好时机。 快速浏览一下Core Concepts并为Serverless.yml Reference添加书签。

I threw in the events section in lines 9:12 so that we can invoke the function with REST call through AWS API Gateway endpoint. Serverless framework will do all the Gateway magic.

我将events部分放在9:12行中,以便我们可以通过AWS API Gateway端点通过REST调用来调用该函数。 无服务器框架将完成所有网关魔术。

Note that this default configuration instructs API Gateway to pass the REST POST call with POST body under the body key (details here. When we POST {"first_name": "Santa", "email": "santa@mad.russian.xmas.com"}, the event passed to the Lambda is:

请注意,此默认配置指示API网关通过body密钥下的POST正文传递REST POST调用( 详细信息 。 此处 ,当我们POST {"first_name": "Santa", "email": "santa@mad.russian.xmas.com"} ,传递给Lambda的事件是:

..."body": {    "first_name": "Santa",     "email": "santa@mad.russian.xmas.com"}

Knowing the input data structure is important to map it to the action input parameters. It’s intuitive: input represents event parameter of AWS Lambda programming model(BTW should we call it event? Vote with a PR!).

知道输入数据结构对于将其映射到动作输入参数很重要。 直观: input代表AWS Lambda编程模型的 event参数(顺便说一句,我们应该将其称为event吗?请投票给PR!)。

Jinja is used to map the inputs; our JavaScript friends who're less familiar with this common Python tool find it intuitive enough in simple cases; and Stack-overflow is full of magic Jinja tricks.

Jinja用于映射输入; 不熟悉此通用Python工具JavaScript朋友会发现它在简单情况下足够直观; 而Stack-overflow充满了神奇的Jinja技巧。

In lines 16:17 of serverless.yml I map the two parameters from input body to desired action input parameters. Optionally, you can also form a function output from action results. I’ll keep it simple for now (line 20:22) and save more tricks for later.

中的行16:17 serverless.yml我从输入体的两个参数所需的操作输入参数映射。 您也可以选择从操作结果中形成函数输出。 我现在将其保持简单(第20:22行),并保存更多技巧以供日后使用。

To keep the config separate, I created a file env.yml that and put my config parameters in it:

为了使配置分开,我创建了一个文件env.yml并将其配置参数放入其中:

# ./env.yml# WARNING: Don't commit to Github :)slack:  admin_token: "xoxs-111111111111-..."  organization: "my-team"

Then I used it in serverless.yml like this: admin: ${file(env.yml):slack}. Note how this syntax puts the object from the key in the file to the key in serverless.yml.

然后,我用它在serverless.yml这样的: admin: ${file(env.yml):slack} 。 请注意,此语法如何将对象从文件中的密钥放入serverless.yml的密钥。

Ok, that’s it! The function is ready to fly to AWS with sls deploy. But I take it sloooow. Step by step. First, I’ll package it locally.

好的,就是这样! 该功能已准备就绪,可以通过sls deploy转到AWS。 但是我觉得这很糟糕 。 一步步。 首先,我将其打包在本地。

sls package

The very first time takes a long time as this is the time when the plugin installs its runtime dependencies. It pulls the Docker images from the Hub. It installs StackStorm runners — the code that knows how to run StackStorm Exchange packs. It pulls the slack pack from Exchange. It installs slack pack python dependencies. It does a lot of work for us, and it takes time. Good news: it's only the first time.

第一次需要很长时间,因为这是插件安装其运行时依赖项的时间。 它从集线器中提取Docker映像。 它安装了StackStorm运行程序—该代码知道如何运行StackStorm Exchange包。 它将slack包从Exchange中拉出来。 它安装了slack pack python依赖项。 它为我们做了很多工作,而且需要时间。 好消息:这只是第一次。

Oh, did I mention that you must be connected? Or do we assume internet connection a basic commodity like breathing air and electric power? At least before FCC repeals Network Neutrality? So yes, you need internet connection to live in the serverless world.

哦,我是否提到您必须连接? 还是我们假设互联网连接是呼吸空气和电力之类的基本商品? 至少在FCC取消网络中立性之前? 因此,是的,您需要Internet连接才能生活在无服务器的世界中。

Now let’s run this locally.

现在让我们在本地运行它。

sls stackstorm docker run --function InviteSlack --verbose \--data \'{"body": {"first_name": "Santa", "email": "santa@mad.russian.xmas.com"}}'

Local runs happen in a container — you’ll see Spin Docker container to run a function CLI output. It takes a bit longer, but ensures that the execution environment matches AWS lambda very closely, so better safe than sorry.

本地运行在容器中进行-您将看到Spin Docker container to run a function CLI输出。 这需要花费更长的时间,但是可以确保执行环境非常紧密地匹配AWS lambda,因此比遗憾更安全。

When I debug input and output parameter transformations, I may not want to call the actual function, like in case of Slack rate-limiting API. Use --passthrough parameter that tells the plugin to do the dry-run and skip the action invocation.

当我调试输入和输出参数转换时,我可能不想调用实际函数,例如使用Slack速率限制API的情况。 使用--passthrough参数,告诉插件进行空运行并跳过动作调用。

Now we are really ready. Let’s deploy the function to AWS, and run it “serverless”.

现在我们已经准备好了。 让我们将该功能部署到AWS上,然后“无服务器”运行它。

sls deploy

It will take some while — now it’s serverless (and honestly, our bundle is a bit bloated, patience! plugin developers are currently busy solving other problems, we will optimize it as soon as we can)

这将需要一些时间-现在它已经是无服务器的了(老实说,我们的捆绑包有点,肿,耐心!插件开发人员目前正在忙于解决其他问题,我们将尽快对其进行优化)

PRO TIP: if something goes wrong at this point, most likely something is not right with your AWS setup. Go back to “Getting Ready, step 2”. Read Serverless Installation doc. Google, Stack-overflow, Serverless Gitter channel or Forum.

专业提示:如果此时出现问题,则很可能是您的AWS设置不正确。 返回到“准备就绪,第2步”。 阅读无服务器安装文档。 Google,堆栈溢出,无服务器Gitter频道或论坛 。

You might be curious to see how it looks in the AWS console. If the PRO in you is saying “no, you should stay cool and use CLI”, don’t listen. Go indulge yourself, open a browser and take a good look at your Lambda. While there, you might also inspect the API Gateway endpoint that sls created for you.

您可能想知道它在AWS控制台中的外观。 如果您的PRO在说“不,您应该保持冷静并使用CLI”,请不要听。 沉迷于自己,打开浏览器,仔细看一下Lambda。 在此处时,您可能还会检查sls为您创建的API Gateway端点。

But to test it, we’ll go back to terminal. Here is how to run your Lambda with sls:

但是要进行测试,我们将回到终端。 这是使用sls运行Lambda的方法:

sls invoke --function InviteSlack --log --data '{"body": {"first_name": "Santa", "email": "santa@mad.russian.xmas.com"}}'

Finally, let’s POST to the API endpoint. The endpoint was printed at the end of sls deploy and you should have taken notice, but it's OK if you didn't: you can always get it by typing sls info.

最后,让我们发布到API端点。 端点是在sls deploy结束时打印的,您应该已经注意到了,但是如果没有,也可以:通过输入sls info可以始终获得端点。

You curl lovers go ahead use it to POST; be sure to set Content-Type=application/json header. Me - I'll show off with httpie, aka CURL for humans:

curl恋人请继续使用它进行发布; 确保设置Content-Type=application/json标头。 我-我将使用httpie (也称为人类的CURL)进行炫耀:

# DON'T copy-paste! Use YOUR endpoint!
http --json POST  https://YOUR-ENDPOINT.amazonaws.com/dev/invite \email=test@example.com first_name=Dmitri

How did it go? Everything worked, at least for me. Let’s fire yet another most useful slscommand to check the CloudWatch logs:

怎么样了 一切正常,至少对我而言。 让我们启动另一个最有用的sls命令来检查CloudWatch日志:

sls logs --function InviteSlack

Success! And the end of the first episode. Enough for now: Christmas time is here, take it slow, enjoy!

成功! 第一集的结尾。 现在已经足够:圣诞节到了,慢慢来,尽情享受吧!

The code example so far is on Github at 1-add-first-action.

到目前为止的代码示例在Github上的1-add-first-action上 。

Episode 2: Adding more actions

第2集添加更多操作

Hope this helped you learn something new, find something interesting, or provoked some good thoughts. Please share your thoughts in the comments here, or tweet me @dzimine.

希望这可以帮助您学习新知识,发现有趣事物或激发一些好的想法。 请在此处的评论中分享您的想法,或在推特上给我@dzimine 。

翻译自: https://www.freecodecamp.org/news/tutorial-building-a-community-on-boarding-app-with-serverless-stepfunctions-and-stackstorm-b2f7cf2cc419/

七牛服务器入门教程

七牛服务器入门教程_教程:使用无服务器,StepFunction和StackStorm构建社区的入门应用程序…...相关推荐

  1. 游戏找不到服务器无法打开,mordhau雷霆一击无法加入服务器怎么解决_搜不到服务器解决方法...

    mordhau雷霆一击无法加入服务器怎么解决_搜不到服务器解决方法 时间:2020-08-05 11:44:25 责任编辑:花泽香菇 mordhau雷霆一击无法加入服务器-搜不到服务器怎么办-这个游戏 ...

  2. 服务器控件的优点和缺点_什么是无服务器架构? 它的优点和缺点是什么?

    服务器控件的优点和缺点 Serverless, the new buzzword in town has been gaining a lot of attention from the pros a ...

  3. JAVA服务器没回应_Java如何面对无服务器的挑战?

    这是来自jaxcenter组织的一个讨论,谈论了Java在无服务器浪潮冲击下面临的机会和挑战.下面摘录主要部分: Spring推动者Pivotal有一个名为 Riff的函数即服务平台,它是一个开源的. ...

  4. Webservice入门教程_教程目录以及地址

    场景 项目专栏: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37726 实现 1.WebService入门简介教程 https://b ...

  5. linux mysql搭建禅道详细教程_如何在Linux服务器上部署禅道

    目前较受欢迎的开源项目管理软件:禅道. 这是一款国产的优秀开源项目管理软件,基于敏捷项目管理理念开发而成,操作简洁,能够很好地满足目前团队中的产品.开发.测试等人员的使用. 下面详细介绍如何在Linu ...

  6. 利用七牛存储7天远程自动备份LINUX服务器

    受服务器空间制约,我们不可能在VPS上每天都备份一份新的网站数据,一是没必要,二是占空间.我们折中一下,采用星期命名,每次备份将覆盖上星期同一天的文件.从而只备份7份数据,不至于占用特别大的空间. 如 ...

  7. php七牛分片上传_七牛视频切片方案 - 张小超fly的个人空间 - OSCHINA - 中文开源技术交流社区...

    使用七牛 sdk 上传视频并做分片操作. step1 生成 token const qiniu = require("qiniu"); var accessKey = proc.e ...

  8. 七牛 java 加水印_七牛云图片加水印

    目标:用户登录进平台后,他看到的所有图片都要以他的用户名加上水印. 1.首先说下七牛加水印的方法,首先附上官网地址: https://developer.qiniu.com/dora/manual/1 ...

  9. java七牛获取访问路径_七牛回调及回调鉴权

    概述 客户上传文件到七牛后,七牛服务器会响应 200 状态码,响应内容包括 hash 和 key .但是如果客户需要自定义响应内容,则可以通过设置回调来实现. 回调实现 客户端需要在上传 token ...

最新文章

  1. Unity游戏开发技巧集锦2.1.3实现效果
  2. 对GET/POST请求返回cookie中的键值对进行重新组合
  3. 支持向量机原理(一)线性支持向量机
  4. mysql innodb count_MySQL下INNODB引擎的SELECT COUNT(*)性能优化及思考
  5. 【pmcaff】萝卜网高级会员奖品发放开始啦!快去领奖哟·!
  6. java邮箱_java发送邮件(qq邮箱)
  7. Mac 安装 homebrew 流程 以及 停在 Updating Homebrew等 常见错误解决方法
  8. 干货下载:可能是你见过的最全的网络爬虫总结
  9. 达梦数据库代码导出_达梦数据库常见问题-命令行工具-导入导出工具
  10. 程序员思维看爱情是什么?
  11. TP5模型修改器和读取器
  12. Windows XP安装sql2000企业版的办法
  13. 2020学而思笔记小初课程百度云网盘分享下载
  14. python 小说cms系统_零基础小白十分钟用Python搭建小说网站!Python真的强!
  15. gRPC-proto文件写法
  16. 一个非计算机专业的 软考中级 网络工程师考试之路
  17. 谈谈 Spring 中的 NoSuchBeanDefinitionException
  18. MarkMind使用技巧
  19. 结绳中文编程[第一节]
  20. android密码是小黑点,Android自定义密码样式 黑点转换成特殊字符

热门文章

  1. 7天拿到阿里安卓岗位offer,统统给你解决!
  2. go语言调用c 的头文件 so,Golang生成共享库(shared library)以及Golang生成C可调用的动态库.so和静态库.a...
  3. linux 磁盘管理3板斧,Linux磁盘管理三板斧的使用心得
  4. B1922 [Sdoi2010]大陆争霸 最短路
  5. 虚拟机 VMware Workstation12 安装OS X 系统
  6. is 和 == 的区别
  7. TOJ---2621--全排列
  8. Hiv:SQuirrel连接hive配置
  9. docker 网络 不好用 docker: Error response from daemon: failed to create endpoint jovial_wing on network b
  10. net程序员的iPhone开发-MonoTouch