标签: serverless

无服务器框架 - 在 serverless.yml 中启用 X-Ray

有没有办法从 serverless.yml 为 Lambda 函数启用 X-Ray?我在文件中添加了 X-Ray 权限:

  iamRoleStatements:
    - Effect: "Allow"
      Resource: "*"
      Action:
        - "xray:*"
Run Code Online (Sandbox Code Playgroud)

但是 Advanced Tracing 仍然需要在 AWS 控制台中手动启用。

serverless-framework aws-xray serverless

6
推荐指数
2
解决办法
3071
查看次数

Serverless 获取本地函数列表

设想

我正在为本地 Lambda 输出编写单元测试。我不想手动输入所有不同 lambda 函数的名称,而是想要动态生成列表。

sls deploy list functions
Run Code Online (Sandbox Code Playgroud)

将返回部署到 aws 的函数列表,但不返回本地无服务器环境中的函数列表

问题

如何获取本地函数列表?

帮助菜单对于如何运行本地函数很有用,但对于组合本地函数列表却没有帮助。

$ sls --help

Commands
* You can run commands with "serverless" or the shortcut "sls"
* Pass "--verbose" to this command to get in-depth plugin info
* Pass "--no-color" to disable CLI colors
* Pass "--help" after any <command> for contextual help

Framework
* Documentation: https://serverless.com/framework/docs/

config ........................ Configure Serverless
config credentials ............ Configures a new provider profile for the Serverless Framework
create ........................ …
Run Code Online (Sandbox Code Playgroud)

aws-lambda serverless-framework serverless serverless-framework-offline

6
推荐指数
1
解决办法
2913
查看次数

销毁通过Serverless创建的资源,而不会破坏Lambda端点

我在serverless.yml文件中定义了以下资源.它非常适合为我所有不同的开发阶段创建资源.

resources:
  Resources:
    uploadBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:service}-${self:custom.stage}-uploads
    visitsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.visitsTable}
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: visitId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: visitId
            KeyType: RANGE
        ProvisionedThroughput:
            ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
            WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
Run Code Online (Sandbox Code Playgroud)

问题是......如果我sls remove在删除数据库时这样做,它还会删除其他所有内容,包括lambda函数及其api网关端点,我需要保留它们,因为我已经为它们明确设置了策略. 如何告诉无服务器我只想删除数据库或S3或其他任何东西而不是其余的?

我试过的事情:

我在AWS上手动删除了,但是如果你这样做并且执行sls部署它不会再次创建数据库!所以不确定最好的方法来做到这一点......

整个Serverless.yml文件

service: mydomain-api

# Use serverless-webpack plugin to transpile ES6/ES7
plugins:
  - serverless-webpack
  - serverless-domain-manager

custom:
  webpackIncludeModules: true
  stage: ${opt:stage, self:provider.stage}
  visitsTable: "${self:service}-visits-${self:custom.stage}"
  domains:
    prod: api.mydomain.com
    staging: staging-api.mydomain.com
    dev: dev-api.mydomain.com …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda aws-api-gateway serverless-framework serverless

6
推荐指数
2
解决办法
4823
查看次数

将我自己的代码连接到kubernetes中的标准docker镜像的最佳实践

我有很多标准的运行时docker镜像,比如安装了tensorflow 1.7的python3,我想使用这些标准图像来运行一些客户代码.该场景似乎与无服务器非常相似.那么将代码放入运行时泊坞窗的最佳方法是什么?

现在我正在尝试使用持久卷将代码挂载到运行时.但它有很多工作要做.是否有一些解决方案更容易?

UPDATE

谷歌机器学习引擎或floydhub的工作流程是什么.我想我想要的是类似的.他们有一个命令行工具,使本地代码与标准环境相结合.

docker kubernetes tensorflow serverless

6
推荐指数
1
解决办法
199
查看次数

无服务器:如何删除一项功能

我正在使用无服务器在AWS上部署我的API。

在无服务器中,它允许部署一个功能:

sls deploy -f <function name>
Run Code Online (Sandbox Code Playgroud)

但是它不允许删除一个函数:

sls remove // will remove all functions.
Run Code Online (Sandbox Code Playgroud)

有什么方法可以删除不影响其他功能的单个功能?

amazon-web-services node.js serverless

6
推荐指数
1
解决办法
3886
查看次数

Spring Cloud Function是否适合REST API?如何访问GET路径参数?

我是WebFlux和Serverless的新手。我正在尝试通过AWS API网关将REST API创建为无服务器。

该流程将是API网关-> Lambda-> DynamoDB

为了实现API流程,Spring Cloud Function是最佳选择吗?我发现aws-serverless-java-container无缝地完成了这项工作(将事件转换为http请求/响应的包装器)

我浏览了http://cloud.spring.io/spring-cloud-function/single/spring-cloud-function.html上的文档以及https://github.com/spring-cloud/上的一些示例弹簧云功能。但是,我仍然不确定是否可以使用Spring Cloud Function实现API风格。

@Bean
//How path or query params can be mapped?
public Function<Flux<String>, Flux<String>> getEmployeeDetails() {
 // business logic goes here
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中,如何实现GET请求/响应模型。如果我的端点具有/ {dept} / {employee} / {name},那么Spring cloud函数如何在GET请求中接受路径参数?

任何指针都会有所帮助。

spring spring-cloud aws-lambda spring-webflux serverless

6
推荐指数
1
解决办法
1070
查看次数

AWS Lambda Function始终返回null(节点/ Javascript)?

我有一个简单的Lambda函数,该函数应该获取事件数据并将消息发送到SNS主题。

运行时为Node.js 8.10。

这是我完整的Lambda代码:

const AWS = require("aws-sdk");

exports.handler = async (event) => {

const sns = new AWS.SNS();

const emailBody = 
`
New Message

From: ${event.name}
Contact: ${event.contact}

Message: ${event.message}
`;

const snsMessageParams = {
    TopicArn: process.env.snsTopicArn,
    Message: emailBody
};

sns.publish(snsMessageParams, (err, data) => {
    if(err) {
        return err;
    } else {
        return data;
    }
  });
};
Run Code Online (Sandbox Code Playgroud)

每次我运行该函数时,响应总是总是为null。没有错误返回,但我从未从SNS的电子邮件中收到消息,因此这里有问题。我只是不知道是什么。

我能够从SNS控制台以及本地计算机上的Node SDK成功地将消息发布到我的SNS主题。这些完美地工作。通过直接从成功的本地代码和SNS控制台复制并粘贴,我已检查env变量中的snsTopicArn是否正确。

我在Lambda函数上具有执行角色,该角色应允许我在帐户中的任何主题上发布到SNS。在配置Lambda角色以测试所有内容时,我选择了默认的“ SNSPublish”选项。但是,作为参考,以下是我的执行角色的政策:

{
  "roleName": <MyRoleName>,
  "policies": [
    {
       "document": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [ …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services node.js amazon-sns aws-lambda serverless

6
推荐指数
2
解决办法
4220
查看次数

到AWS的Angular Serverless部署会将base-href附加到url,导致重定向到404Error

我正在尝试将angular 7网站部署到无服务器的AWS上。刚开始时,我遵循了本教程:https : //coursetro.com/posts/code/165/Deploying-your-Angular-App-to-a-Serverless-Environment-

部署后,我的url附加了一个额外的“ production / ”,我认为这是由于我的base-href设置所致。

这会导致不必要的重定向到404。有人知道如何避免这种情况吗? 导航菜单效果很好

输入的网址:

https://7z48go76gd.execute-api.ap-southeast-1.amazonaws.com/production

加载后:

https://7z48go76gd.execute-api.ap-southeast-1.amazonaws.com/production/production

我尝试过环境.prod.ts,environment.serverless.ts以及具有不同变体但没有运气的package.json文件。

environment.serverless.ts / environment.prod.ts:

export const environment = {
  production: true,
  BASE_URL: 'https://tj2rdz0qn1.execute-api.ap-southeast-1.amazonaws.com/production',
  // when you deploy your app to your own server you should replace the BASE_URL with the target domain for example:
  // BASE_URL: 'https://site-preview.angular-templates.io',
  baseHref: '/'
};
Run Code Online (Sandbox Code Playgroud)

package.json:

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "lint": "ng lint crc-web",
    "build:client-and-server-bundles": "ng build --prod && ng run crc-web:server:production",
    "build:ssr": "npm …
Run Code Online (Sandbox Code Playgroud)

aws-lambda angular-universal angular serverless

6
推荐指数
1
解决办法
476
查看次数

允许在 Kubernetes 上使用本地库中的图像

我正在遵循教程https://docs.openfaas.com/tutorials/first-python-function/

目前,我有正确的图像

$ docker images | grep hello-openfaas
wm/hello-openfaas                                     latest                          bd08d01ce09b   34 minutes ago      65.2MB
$ faas-cli deploy -f ./hello-openfaas.yml 
Deploying: hello-openfaas.
WARNING! You are not using an encrypted connection to the gateway, consider using HTTPS.

Deployed. 202 Accepted.
URL: http://IP:8099/function/hello-openfaas
Run Code Online (Sandbox Code Playgroud)

有一个步骤预先警告我进行一些设置(我的情况是我正在使用Kubernetes并且minikube不想推送到远程容器注册表,我应该启用 Kubernetes 上本地库中的图像的使用。),我查看提示

see the helm chart for how to set the ImagePullPolicy
Run Code Online (Sandbox Code Playgroud)

我不确定如何正确配置它。最后的结果表明我失败了。

不出所料,我无法访问函数服务,我在 https://docs.openfaas.com/deployment/troubleshooting/#openfaas-didnt-start中找到了一些线索,这可能有助于诊断问题。

$ kubectl logs -n openfaas-fn deploy/hello-openfaas
Error from server (BadRequest): container "hello-openfaas" in pod "hello-openfaas-558f99477f-wd697" is …
Run Code Online (Sandbox Code Playgroud)

kubernetes minikube kubernetes-helm serverless openfaas

6
推荐指数
1
解决办法
1538
查看次数

无法从无服务器框架中的自定义路径加载环境文件

我无法使用无服务器框架加载位于自定义路径中的环境文件。

env 文件保存在项目中的“config/environment”文件夹中,可用的文件是

  • .env
  • .env.dev
  • .env.qa
  • .env.prod

Serverless.yml内容如下

plugins:
   - serverless-dotenv-plugin
custom:
  stage: ${opt:stage, "dev"}
  dotenv:
    basePath: ./config/environment/
    logging: false
Run Code Online (Sandbox Code Playgroud)

触发“无服务器部署”时,出现如下错误

无法解析 serverless.yml:变量解析出错:

  • 无法解析“provider.xxxxxx”处的变量:在“env”源中找不到值,
  • 无法解析“provider.xxxxxx”处的变量:在“env”源中找不到值,
  • 无法解析“provider.xxxxxx”处的变量:在“env”源中找不到值,
  • 无法解析“provider.xxxxxx”处的变量:在“env”源中找不到值,
  • 无法解析“provider.xxxxxx”处的变量:在“env”源中找不到值,

似乎 .env 文件没有被加载,任何帮助将不胜感激。

serverless-framework serverless aws-serverless

6
推荐指数
1
解决办法
1939
查看次数