繁体   English   中英

在本地运行现有的 AWS Lambda

[英]Running existing AWS Lambdas locally

我使用 Visual Studio 在 C# 中创建了 AWS Lambda,它从 API 端点返回一些 JSON。 现在我想在本地运行 lambda。 所有示例都使用 AWS SAM,但它们使用 SAM 模板创建了一个新的 function。

当我运行命令sam local start-lambda ,我收到一条错误消息,指出找不到模板。 所以可以肯定的是,我需要 template.yaml,但我不确定是否有办法为现有的 Lambda 生成此模板?

任何帮助表示赞赏!

查看 AWS 文档中的模板剖析资源

您可能会发现此示例很有用(已大大简化)。 我使用 NodeJS 进行开发,但是在创建 SAM 模板时编程语言之间的差异是微不足道的。 该示例是 API 网关 (HTTP) 事件调用的简单 Lambda function someFunction的概要。


AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: My Serverless Application
Parameters:
  # Manually define this in AWS IAM for just the services needed.
  lambdaExecutionRole:
    Description: 'Required. The role used for lambda execution.'
    Type: 'String'
    Default: 'arn:aws:iam::nnnnnnnnnnnn:role/LambdaExecutionRole'


Globals:
  Function:
    Runtime: nodejs10.x
  #   Environment:
  #     Variables:
  #       NODE_ENV: test
  #       DEBUG: myapp:foo

Resources:

  performSomeFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      FunctionName: performSomeFunction
      Handler: lambda.someFunction
      CodeUri: ./
      Description: description of the function being performed
      MemorySize: 256
      Timeout: 60
      Role:
        Ref: lambdaExecutionRole
      Events:
        # API Gateway proxy endpoint.
        ProxyApiRoot:
          Type: Api
          Properties:
            Path: '/'
            Method: ANY
        ProxyApiGreedy:
          Type: Api
          Properties:
            Path: '/{proxy+}'
            Method: ANY

当您开始使用 AWS Lambda 时,要记住的重要概念之一是您的 function 将如何被触发。 函数由不同类型的事件触发,并且可以有许多不同类型的事件 我倾向于使用 API 网关、简单队列服务和 CloudWatch 事件来触发我的,但这完全取决于您的用例。

原来可以导出Lambda function,得到生成的.yaml模板,正是我需要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM