I'm trying to run simple integration between Lambda and API Gateway with AWS SAM. I want to customize the input for lambda - apply some requestTemplates. But those seem to be ignored.
Running with:
sam local start-api
curl -v -XPOST -H "Content-type: application/json" -d '{"jarmil":"prdel"}' http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)
The output is:
START RequestId: 43594e8a-c3af-4f47-9d85-6c605131f02a Version: $LATEST
Processing event {'httpMethod': 'POST', 'body': '{"jarmil":"prdel"}', 'resource': '/', 'requestContext': {'resourcePath': '/', 'httpMethod': 'POST', 'stage': 'prod', 'identity': {'sourceIp': '127.0.0.1:53210'}}, 'queryStringParameters': {}, 'headers': …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 SAM 部署 AWS Lambda 函数。我想要做的是通过部署本地源代码来更新现有的 lambda 函数。
为了做到这一点,我在 template.yaml 中将现有的 lambda 函数名称指定为“FunctionName”,如下所示。但是,'FunctionName' 只支持创建新函数,不支持更新到现有函数。 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionname
是否有任何方法可以在 SAM 中指定函数名称以更新 lambda 函数?
[模板.yaml]
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
HelloWorld:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'hello_world'
Description: ''
Handler: index.handler
MemorySize: 256
Role: 'arn:aws:iam::368834739507:role/lambda_basic_execution'
Runtime: nodejs6.10
Timeout: 120
Run Code Online (Sandbox Code Playgroud) 描述: 我正在尝试定义无服务器 API 资源。但是在使用函数 ImportValue 定义 swagger 规范文件的位置时遇到麻烦。
重现问题的步骤:
我无法在 Location 中定义AWS::Serverless::Api具有嵌套函数的资源ImportValue。我尝试了以下三种方法,它们都不起作用。
注意:堆栈参数定义正确,存在其他堆栈的导出值。为简洁起见,这里不显示它们。
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub ${AWS::StackName}-API
StageName: !Ref ApiGatewayStageName
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location:
Fn::Sub:
- s3://${BucketName}/${SwaggerSpecificationS3Key}
- BucketName:
Fn::ImportValue:
!Sub "${EnvironmentName}-dist-bucket-${AWS::Region}"
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub ${AWS::StackName}-API
StageName: !Ref ApiGatewayStageName
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location:
Fn::Sub:
- s3://${BucketName}/${SwaggerSpecificationS3Key}
- BucketName:
!ImportValue 'dev-dist-bucket-us-east-1'
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub ${AWS::StackName}-API
StageName: !Ref ApiGatewayStageName
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: …Run Code Online (Sandbox Code Playgroud) 我有一个新项目,它需要的服务数量相对较少,可能只有 10 个或更少(因此将每个项目放在单独的项目存储库中并不经济)。每项服务都将通过 SAM 模板定义为 AWS::Serverless::Function。我的问题是:组织或构建此类项目的推荐方法是什么?
目前的结构是:
|- src
|- lambdas
|- service-one
|- stuff
|- package.json
|- service-two
|- stuff
|- package.json
|- other-stuff
|- test
|- package.json
Run Code Online (Sandbox Code Playgroud)
有没有办法避免让每个 lambda 充当自己的子项目package.json,等等?
当我运行我的 lambda 代码时,我收到以下错误:
The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access.
我主要遵循此使用 aws-sam-cli 创建堆栈,模板的相关部分在代码下方。
相关代码是:
const ssm = new AWS.SSM();
const param = {
Name: "param1",
WithDecryption: true
};
const secret = await ssm.getParameter(param).promise();
Run Code Online (Sandbox Code Playgroud)
template.yaml 文件的相关部分是:
KeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: 'param1Key'
TargetKeyId: !Ref Key
Key:
Type: AWS::KMS::Key
Properties:
KeyPolicy:
Id: default
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda aws-sam-cli aws-serverless serverless-application-model
我正在尝试以编程方式设置阶段作为我的 AWS API Gateway 部署的一部分。我正在使用 SAM CLI。cloudformation 文档给出了定义:
DeploymentId 阶段指向的部署的 ID。
要求:是
类型:字符串
更新要求:无中断
和代码示例:
Resources:
Prod:
Type: AWS::ApiGateway::Stage
Properties:
StageName: Prod
Description: Prod Stage
RestApiId: !Ref MyRestApi
DeploymentId: !Ref TestDeployment ## <===== this
DocumentationVersion: !Ref MyDocumentationVersion
ClientCertificateId: !Ref ClientCertificate
Variables:
Stack: Prod
MethodSettings:
- ResourcePath: /
HttpMethod: GET
MetricsEnabled: 'true'
DataTraceEnabled: 'true'
- ResourcePath: /stack
HttpMethod: POST
MetricsEnabled: 'true'
DataTraceEnabled: 'true'
ThrottlingBurstLimit: '999'
- ResourcePath: /stack
HttpMethod: GET
MetricsEnabled: 'true'
DataTraceEnabled: 'true'
ThrottlingBurstLimit: '555'
Run Code Online (Sandbox Code Playgroud)
..但没有关于价值TestDeployment指向什么的背景。 …
我是AWS和Go的新手,我正在尝试通过AWS SAM CLI执行Lambda函数。但是每次我尝试这样做时,都会出现以下错误:
I0517 07:51:11.052078 13 main.go:62] Thumbnail Lambda successfully started
I0517 07:51:13.696304 13 utils.go:99] Needed directories successfully created
2019-05-17 09:51:14 Function 'Thumbnail' timed out after 3 seconds
2019-05-17 09:51:14 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received:
Run Code Online (Sandbox Code Playgroud)
因为它很敏感,所以我不想复制在HTTP请求中传递的信息。
知道如何修改这3秒钟的超时时间吗?
按照 AWS 文档中的步骤操作
https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html
使用 aws-stepfuncitons-local docker 容器
我在最后一步收到连接被拒绝的错误
2019-05-28 12:37:05.004: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test :
{
"Type":"ExecutionFailed",
"PreviousEventId":5,
"ExecutionFailedEventDetails":
{
"Error":"Lambda.SdkClientException",
"Cause":"Unable to execute HTTP request: Connect to 127.0.0.1:3001 [/127.0.0.1] failed: Connection refused (Connection refused)"
}
}
Run Code Online (Sandbox Code Playgroud)
任何有关如何解决它的帮助将不胜感激。
当使用 AWS SAM CLI 构建无服务器应用程序时,它神奇地定位依赖项并将它们全部安装为“构建”步骤。例如,使用 NodeJS 应用程序:
$> sam build
Building resource 'HelloWorldFunction'
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
$>
Run Code Online (Sandbox Code Playgroud)
查看官方文档,他们很乐意简单地将其视为魔术,并说:
遍历应用程序中的函数,查找
requirements.txt包含依赖项的清单文件(例如),并自动创建可以部署到 Lambda 的部署工件
但是,如果我有一个超出清单文件中指定的依赖项怎么办?如果我的代码依赖于编译的二进制文件或静态数据文件怎么办?
我想添加额外的构建步骤,以便在我运行sam build时编译这些文件或适当地复制它们。有没有办法做到这一点?
从这个答案我了解到 SAM 是 Cloudformation 的一种转换。
有没有办法通过控制台、CLI 或其他方式从 SAM 模板获取转换后的 Cloudformation 模板?
amazon-web-services aws-cloudformation aws-sam-cli aws-sam serverless-application-model
aws-sam-cli ×10
aws-lambda ×4
aws-sam ×2
serverless-application-model ×2
go ×1
lambda ×1
sam ×1