标签: serverless

如何在无服务器中将 vpc 端点与 ses 一起使用

我在没有 nat 网关/互联网访问的 vpc 中部署了功能。目标:从此函数通过 SES 发送电子邮件(在 vpc 中)

我尝试过使用公共私有子网和 nat 网关来发送电子邮件,效果很好。但我正在尝试通过 VPC 端点使用它。我已经创建了一个电子邮件 vpc 端点,但不确定如何在 serverless.yml 中配置它。已尝试按照https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/中所述设置配置

但没有任何作用,因为没有提到 ses。

amazon-ses aws-sdk-nodejs serverless

5
推荐指数
2
解决办法
5668
查看次数

使用 Serverless Next JS 在同一路由上使用不同的 Content-Type

我想知道无服务器(部署在 Vercel 上)Next JS 是否可以实现以下场景:

/product/[id].tsx当您发送带有 header 的请求时,我有一条路线Accept: text/html,我希望它通过 React 页面来经历正常的 Next JS 流程。但是,当使用 给出请求时Accept: application/json,我希望它返回 JSON 表示形式。

我通过使用为 Express 编写的一些自定义中间件(见下文)来完成此任务,但我还想将其部署在 Vercel 上,而 Vercel 不适用于自定义 Express 实现。

那么问题来了,在无服务器环境下是否可以做到这一点?Next JS React 页面之一可以返回纯 JSON,还是可以从 Next JS Api 路由返回 React?或者还有其他方法可以实现此目的吗?

服务器.ts

import express, { Request, Response } from "express";
import next from 'next'
import { parse } from 'url'

const port = parseInt(process.env.PORT || "3000", 10);
const dev = process.env.NODE_ENV !== "production";

async function run(): Promise<void> {
  const …
Run Code Online (Sandbox Code Playgroud)

javascript node.js next.js serverless vercel

5
推荐指数
1
解决办法
4430
查看次数

找出 lambda 函数从哪个 IP 运行

我有一个从 VPC 运行的 lambda 函数。我们为 HA 配置了三个可用区。我想知道每个 Lambda 调用是从哪个可用区运行的。

我的 lamdba 使用 python 3.7 作为运行时

我试过这个

import socket    
hostname = socket.gethostname()    
IPAddr = socket.gethostbyname(hostname)    
print("Your Computer Name is:" + hostname)    
print("Your Computer IP Address is:" + IPAddr) 
Run Code Online (Sandbox Code Playgroud)

但这给了我:

Your Computer Name is:169.254.128.117
Your Computer IP Address is:169.254.128.117
Run Code Online (Sandbox Code Playgroud)

这没有帮助。

我如何知道 lambda 函数正在使用什么私有 IP?

python amazon-web-services amazon-vpc aws-lambda serverless

5
推荐指数
1
解决办法
5870
查看次数

无服务器:将文件导入自定义+其他变量

我有一个serverless.common.yml, 其属性应由所有服务共享,其中:

service: ixxxx
custom:
  stage: ${opt:stage, self:provider.stage}
  resourcesStages:
    prod: prod
    dev: dev
  resourcesStage: ${self:custom.resourcesStages.${self:custom.stage}, self:custom.resourcesStages.dev}

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

并且,另一个serverless.yml位于 services 文件夹中,它使用公共文件的属性:

...

custom: ${file(../../serverless.common.yml):custom}
...
environment:
    stage: ${self:custom.stage}
...
Run Code Online (Sandbox Code Playgroud)

这样,我就可以毫无问题地访问自定义变量(从公共文件)。现在,我想继续将此文件导入到自定义文件中,但添加与此服务相关的新变量,所以我尝试了:

custom: 
  common: ${file(../../serverless.common.yml):custom}
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    dockerizePip: non-linux
Run Code Online (Sandbox Code Playgroud)

似乎可以访问,例如:

environment:
    stage: ${self:custom.common.stage}
Run Code Online (Sandbox Code Playgroud)

但现在,我收到错误:

 Serverless Warning --------------------------------------

  A valid service attribute to satisfy the declaration 'self:custom.stage' could not be found.


 Serverless Warning --------------------------------------

  A valid service …
Run Code Online (Sandbox Code Playgroud)

serverless-framework serverless

5
推荐指数
1
解决办法
886
查看次数

无服务器:根配置错误:无法识别的属性“stepFunctions”

我有一些奇怪的错误,我无法找出原因,你能帮助我吗?

...
无服务器:警告:无法找到名为:TypeScriptPlugin
无服务器:根配置错误:无法识别的属性“stepFunctions”
...

无服务器.yml

service:
  name: service-name

plugins:
  - serverless-localstack
  - serverless-step-functions
  - serverless-pseudo-parameters
  - serverless-webpack

custom:
  webpackIncludeModules: true
  localstack:
    stages:
      - local
    host: http://localhost
    edgePort: 4566
    autostart: true
    lambda:
      mountCode: false
    debug: true
    docker:
      sudo: true

provider:
  configValidationMode: off
  deploymentBucket:
    name: local
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage, "dev"}
  region: ${env:AWS_REGION, "us-east-1"}
  logRetentionInDays: 30

functions:
  ...

stepFunctions:
  ...
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "service-name",
  "version": "0.119.0",
  "description": "Service decription.",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-step-functions serverless localstack

5
推荐指数
1
解决办法
8654
查看次数

使用 Azure 函数的 Azure SignalR 无服务器 OnConnected 触发器(传统模型)

我将 Azure SignalR 服务与 Azure Functions 结合使用,并且有以下代码:

    public class SignalRHubFunction
    {
        [FunctionName("SignalRConnected")]
        public async Task Run([SignalRTrigger("myhubname", "connections", "connected", ConnectionStringSetting = "AzureSignalRConnectionString")] InvocationContext invocationContext, ILogger logger)
        {
            logger.LogInformation($"{invocationContext.ConnectionId} connected");
        }
    }
Run Code Online (Sandbox Code Playgroud)

我很难触发“OnConnected”事件。仅提供基于类的模型的示例。而且这些文档对我来说并没有真正的帮助。

文档告诉我构造函数的类别SignalRTrigger参数应该是: connectionsmessages。所以我使用连接

该值必须设置为要触发的功能的消息类别。该类别可以是以下值之一: 连接:包括连接和断开连接事件 消息:包括除连接类别中的事件之外的所有其他事件

我不太明白文档中事件参数的含义

该值必须设置为消息事件才能触发该功能。对于消息类别,事件是客户端发送的调用消息中的目标。对于连接类别,仅使用已连接和已断开连接。

我猜他们是说你可以在连接断开之间进行选择。

然而,使用上面的代码永远不会触发触发器。有什么想法吗?

signalr asp.net-core azure-functions serverless

5
推荐指数
1
解决办法
2447
查看次数

如何使用 serverless.yml 创建 dynamodb 表并使用 python boto3 删除其中的项目?

我使用 serverless.yml 创建了 dynamodb 表,如下所示:

resources:
  Resources:
    myTable:
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      Properties:
        TableName: myTable
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: firstname
            AttributeType: S
          - AttributeName: lastname
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
          - AttributeName: firstname
            KeyType: RANGE
        BillingMode: PAY_PER_REQUEST
        SSESpecification:
          SSEEnabled: true
Run Code Online (Sandbox Code Playgroud)

但我有这个问题:

发生错误:myTable - 一个或多个参数值无效:KeySchema 中的属性数量与 AttributeDefinitions 中定义的属性数量不完全匹配(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;请求 ID:PEI9OT7E72HQN4N5MQUOIUQ18JVV4KQNSO5AEMVJF66Q9ASUAAJG;代理: 无效的)。

您能帮我使用 serverless.yml 创建 dynamodb 表吗?如何使用 python boto3 删除此表中名字为“First”的项目?

python amazon-dynamodb boto3 aws-lambda serverless

5
推荐指数
1
解决办法
1772
查看次数

AWS Cognito 与 CDK UserPool MFA

有人可以告诉我是否可以创建一个userPool需要 MFA、禁用 SMS MFA 但启用 OTP MFA 的系统。

在AWS控制台上,这似乎不是一个问题,但由于某种原因,通过CDK,它不太高兴。

我尝试更新现有用户池并创建一个新用户池。

new UserPool(this, 'foo-user-pool', {
    userPoolName: 'foo',

    selfSignUpEnabled: false,
    passwordPolicy: {
        minLength: 12,
        requireDigits: true,
        requireLowercase: true,
        requireSymbols: true,
        requireUppercase: true,
        tempPasswordValidity: cdk.Duration.days(7)
    },
    accountRecovery: AccountRecovery.EMAIL_ONLY,
    enableSmsRole: false,
    mfa: Mfa.REQUIRED,
    mfaSecondFactor: {
        sms: false,
        otp: true
    },

    signInAliases: {
        email: true,
    },
    autoVerify: {
        email: true,
    },
})
Run Code Online (Sandbox Code Playgroud)

给我以下错误消息并且已经有一段时间了......

SMS configuration and Auto verification for phone_number are required when MFA is required/optional (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: …
Run Code Online (Sandbox Code Playgroud)

node.js amazon-cognito serverless aws-cdk

5
推荐指数
0
解决办法
812
查看次数

如何在没有内联代码的情况下使用 lambda 函数部署 cloudformation?

lambda 函数大小超过 4096 个字符,因此我无法将 lambda 函数部署为 cloudformation 模板中的内联代码。

( https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html )

压缩文件

您的源代码最多可以包含 4096 个字符。对于 JSON,必须使用反斜杠转义引号和特殊字符,例如换行符 (\n)。

我必须先将其压缩,上传到 s3 存储桶,在 cloudformation 中设置 s3 存储桶和文件详细信息,然后部署它。

我找不到一种使用一个命令进行部署的方法。如果我更新 lambda 代码,我必须重复上述步骤

但借助 AWS SAM 或无服务器框架,他们可以部署 lambda 函数而无需内联代码。

唯一的问题是,AWS SAM 或无服务器框架默认创建 API 网关,我不需要创建它

对我有什么解决方案或建议吗?

更新

SAM 支持在不创建 API 网关的情况下部署 lambda 函数。所以问题解决了

aws-cloudformation aws-lambda serverless-framework serverless aws-sam

5
推荐指数
1
解决办法
8239
查看次数

未为 aws sam cli 配置 Python

我正在按照本教程构建 SAM 应用程序:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html

\n

当我这样做时sam build,我收到以下错误

\n
\xe2\x9d\xaf sam build\nBuilding codeuri: hello_world/ runtime: python3.8 metadata: {} functions: [\'HelloWorldFunction\']\n\nBuild Failed\nError: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations  : [\'/usr/bin/python\'] which did not satisfy constraints for runtime: python3.8. Do you have python for runtime: python3.8 on your PATH?\n
Run Code Online (Sandbox Code Playgroud)\n

我通过这样做检查了我的Python

\n
\xe2\x9d\xaf which python\npython: aliased to python3\n
Run Code Online (Sandbox Code Playgroud)\n

当我做 python 版本时,我得到了这个

\n
\xe2\x9d\xaf python --version\nPython 3.8.2\n
Run Code Online (Sandbox Code Playgroud)\n

那么缺少什么以及如何解决这个问题呢?

\n

python amazon-web-services aws-lambda serverless aws-sam

5
推荐指数
3
解决办法
1万
查看次数