Serverless

5分钟Serverless实践:构建无服务器的图片分类系统

别说谁变了你拦得住时间么 提交于 2019-12-12 23:21:36
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前 言 在过去“5分钟Serverless实践”系列文章中,我们介绍了如何构建无服务器API和Web应用,从本质上来说,它们都属于基于APIG触发器对外提供一个无服务器API的场景。现在本文将介绍一种新的设计模式:基于事件的实时数据处理。为了更形象地描述,我们以图片分类为例,先介绍通过APIG触发器如何构建一个图片分类的Web应用,再介绍通过OBS触发器如何构造一个实时的图片分类系统。 Serverless 优势 相比于传统的架构,无服务器架构具有如下优点: 1. 无需关注任何服务器,只需关注核心业务逻辑,提高开发和运维效率; 2. 事件触发,灵活扩展; 3. 函数运行随业务量弹性伸缩,按需付费,执行才计费,对于负载波峰波谷非常明显的场景可以减少大量成本; 4. 通过简单的配置即可连通函数工作流和其它各云服务,甚至云服务和云服务; 构建无服务器的图片分类Web应用 像以往的文章介绍的那样,serverless很擅长构建一个Web应用,如下图,该系统会将用户上传的图片进行分类,并打上类别标签。 我们可以通过 函数工作流服务 来快速构建这个系统,并且完全无需关注服务器,且弹性伸缩运行、按需计费,如图: 创建函数,在函数中调用华为云图片分析服务的图片标签接口,给图片打标签分类。再为该函数配置一个APIG触发器

Using serverless-mocha-plugin to test dynamic endpoint

陌路散爱 提交于 2019-12-12 15:16:54
问题 I am creating an API application in NodeJS using the Serverless framework. I have installed the serverless-mocha-plugin and am trying to create some unit tests for my functions. In my serverless.yml file, I have the following endpoints: ... equipmentGetAll: handler: ./api/equipment/equipment.getAll events: - http: path: equipment method: get cors: true equipmentGetOne: handler: ./api/equipment/equipment.getOne events: - http: path: equipment/{po_number} method: get cors: true ... When testing

How to implement exponential backoff in Azure Functions?

断了今生、忘了曾经 提交于 2019-12-12 11:35:39
问题 How to implement exponential backoff in Azure Functions? I have a function that depends on external API. I would like to handle the unavailability of this service using the retry policy. This function is triggered when a new message appears in the queue and in this case, this policy is turned on by default: For most triggers, there is no built-in retry when errors occur during function execution. The two triggers that have retry support are Azure Queue storage and Azure Blob storage. By

continuous database sync with azure functions

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:58:38
问题 I am developng an app with xamarin and azure serverless functions as backend for the app. I will be syncing map coordinates from the users in real time with a database on the cloud . i.e : taking coordinates from all users and then pushing the updated coordinates to all users at the same time, continuously so that all users can see live location of each other. So I have to call an azure function in continous loop in order to sync database with cloud. so it can check db after every, 4-5 secs.

Public IP address for AWS API Gateway & Lambda (no VPC)

柔情痞子 提交于 2019-12-11 17:56:24
问题 I have provisioned an AWS API Gateway and created a Lambda function to connect to an external REST API. The API Gateway & Lambda is not in a VPC so the egress IP address is random. The challenge I have is the external REST API is behind a firewall, which requires the IP address or subnet of the Lambda to be whitelisted. I have looked at the AWS IP Address page (below), however there is no explicit mention of either API Gateway or Lambda. https://docs.aws.amazon.com/general/latest/gr/aws-ip

GitLab Serverless deployment fails due to “nil watch interface”

为君一笑 提交于 2019-12-11 17:22:49
问题 The deployment to a Kubernetes Cluster created in GitLab with default values after specifying stages: - build - deploy build: stage: build image: name: gcr.io/kaniko-project/executor:debug entrypoint: [""] only: - master script: - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE

Getting double quotes when returning html

我怕爱的太早我们不能终老 提交于 2019-12-11 15:54:23
问题 I have below route to return privacy policy for my app. const html = `<html><body><div>dsfdsfsfdsfsfsdfdsf</div></body></html>` const handler = (request, reply) => { try { return reply(html) } catch (err) { return reply({ success: false, message: err.message, data: [] }) } } const routeConfig = { method: 'GET', path: '/privacy-policy', config: { description: 'Creates a task.', notes: ['On success, returns { "data": [ { "tasks" } ]}'], handler } } However when I am returning the html content I

Javascript serverless error of json object with async return

我怕爱的太早我们不能终老 提交于 2019-12-11 15:54:08
问题 First, I write lambda function like: function jsonResponse(status, header, body) { return { headers: Object.assign(header, { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json;charset=utf-8' }), statusCode: status, body: JSON.stringify(body) } } export const hello = async (event, context, cb) => { const rep = { message: 'v1.0', event: event }; cb(null, jsonResponse(201, {}, rep)); return; }; It work OK, but according the serverless forum the serverless office forum and the

Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in Azure Functions

不打扰是莪最后的温柔 提交于 2019-12-11 06:45:40
问题 I am refering a C# library project from my Azure Function (Service bus queue trigger). The library is referencing the Newtonsoft nuget version 10.0.1. While running the function locally on my visual studio, it gives this error . {"Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.":"Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken

Native Serverless vs Serverless Express

会有一股神秘感。 提交于 2019-12-11 06:07:50
问题 Right now, I am following a guide prepared from Serverless Stack Team. They are using React and lots of AWS features like lambda and API getaway . In order to practice it, I am re-writing one of my old Express example with the Serverless stack. I also saw a library or tool called aws-serverless-express . This library or tool allows you to run your express app in a way that serverless form. It will be a weird question, but I was wondering the difference between native serverless build and