[英]Running existing AWS Lambdas locally
我使用 Visual Studio 在 C# 中創建了 AWS Lambda,它從 API 端點返回一些 JSON。 現在我想在本地運行 lambda。 所有示例都使用 AWS SAM,但它們使用 SAM 模板創建了一個新的 function。
當我運行命令sam local start-lambda
,我收到一條錯誤消息,指出找不到模板。 所以可以肯定的是,我需要 template.yaml,但我不確定是否有辦法為現有的 Lambda 生成此模板?
任何幫助表示贊賞!
您可能會發現此示例很有用(已大大簡化)。 我使用 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.