我想serverless.yml在不同的环境中重用我的(dev,test,prod).
在配置中我有:
provider:
name: aws
stage: ${opt:stage, 'dev'}
environment:
NODE_ENV: ${self:provider.stage}
Run Code Online (Sandbox Code Playgroud)
现在价值将是dev,test或prod(全部为小写).
有没有办法将它转换为UpCase()的方式,输入和self:provider:stage将保持原样(即小写),但NODE_ENV的值将是大写?
我有一个React应用程序,试图从AWS访问无服务器。但是我有下面的错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.test.com' is therefore not allowed access. The response had HTTP status code 502.
Run Code Online (Sandbox Code Playgroud)
端点网址为https://key.execute-api.ap-southeast-2.amazonaws.com/dev/samplefunction
在serverless.yml上的设置是
login:
handler: login.login
events:
- http:
path: login
method: post
cors:
origin: 'https://admin.differentdomain.com'
headers:
- MY_CUSTOM_HEADER
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
Run Code Online (Sandbox Code Playgroud)
我还有其他地方需要进行CORS配置吗?
我想使用无服务器框架和 AWS 设置自定义域。
这就是我在 serverless.yml 中的内容
service: chapiLabs-rest-api
plugins:
- serverless-domain-manager
- serverless-express
custom:
customDomain:
domainName: chapitime.chapilabs.com
basePath: ''
stage: ${self:provider.stage}
certificateName: '*.chapilabs.com'
createRoute53Record: true
package:
exclude:
- node_modules
include:
- dist
provider:
name: aws
runtime: nodejs8.10
webpackIncludeModules:
forceInclude:
- mysql
- mysql2
- sequelize
functions:
get:
handler: dist/get.get
events:
- http:
path: v1/client/{id}
method: get
request:
parameters:
paths:
id: true
create:
handler: dist/auth.auth
events:
- http:
path: v1/auth
method: post
Run Code Online (Sandbox Code Playgroud)
我使用这个 npm 包作为插件:https : //github.com/amplify-education/serverless-domain-manager
我使用 CloudFlare 通过 …
是否有能力使用GraalVM在AWS Lambda函数中运行Java?我阅读了许多关于使用GraalVM AOT(提前)编译功能的Java应用程序冷启动的文章,并减少了持续时间,我想尝试在我的AWS Lambda项目中使用它.
我的serverless.yml文件中的这些行有问题。我正在使用无服务器插件serverless-single-page-app-plugin。
# CustomOriginConfig:
# HTTPPort: 80
# HTTPSPort: 443
# OriginProtocolPolicy: https-only
## In case you want to restrict the bucket access use S3OriginConfig and remove CustomOriginConfig
S3OriginConfig:
OriginAccessIdentity: origin-access-identity/cloudfront/E127EXAMPLE51Z
Run Code Online (Sandbox Code Playgroud)
我想使用s3OriginConfig和禁用通过 S3 存储桶的访问。我可以手动执行此操作。但我想得到如下图所示的效果:

尝试使用 AWS Lambda 在 elasticsearch 中索引一些数据。堆栈跟踪
TypeError [ERR_INVALID_ARG_TYPE]: 在 Object.createHmac (crypto.js:122:10) 的 new Hmac (internal/crypto/hash.js:84:11) 中,“key”参数必须是 string、TypedArray 或 DataView 类型之一在 Object.hmac (/home/projects/serverless-todo-app/.webpack/service/src/indexer/createIndex.js:698:30) 在 Object.getSigningKey (/home/projects/serverless-todo-app/. webpack/service/src/indexer/createIndex.js:7109:8) 在 V4.signature (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12708:36) 在 V4。授权 (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:12703:36) 在 V4.addAuthorization (/home/projects/serverless-app/.webpack/service/src/indexer /createIndex.js:12645:12) 在 ElasticsearchService.put (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:8150:12) 在进程 (/home/projects/serverless-app/.webpack/service/src/indexer/createIndex.js:8115:24) 在 BbPromise (/usr /local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) 在 AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index .js:521:12) 在 AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:152:19) 来自之前的事件:在 Object.invoke:local:调用 [作为钩子] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)24) 在 BbPromise (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) 在 AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/ plugins/aws/invokeLocal/index.js:521:12) 在 AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:152:19) 来自之前的事件:在 Object.invoke:local:invoke [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:34:10)24) 在 BbPromise (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:567:30) 在 AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/ plugins/aws/invokeLocal/index.js:521:12) 在 AwsInvokeLocal.invokeLocal …
这个问题与Serverless offline not getting route几乎相同,但由于没有回答这个问题,我再次问。我正在尝试关注这篇文章https://medium.com/@awesome1888/how-to-use-serverless-locally-with-webpack-and-docker-5e268f71715,了解如何使用无服务器部署 Lambda 函数。
我有一个具有以下结构的目录:
> tree -I node_modules
.
??? package-lock.json
??? package.json
??? serverless.yml
??? src
? ??? handler.js
? ??? index.js
??? webpack.config.js
Run Code Online (Sandbox Code Playgroud)
哪里serverless.yml读
service: my-first-lambda
plugins:
- serverless-webpack
- serverless-offline
provider:
name: aws
runtime: nodejs10.x
region: us-east-1
stage: dev
functions:
hello:
handler: src/handler.main
events:
- http:
path: /hello
method: any
custom:
webpack:
includeModules: true
Run Code Online (Sandbox Code Playgroud)
src/index.js 阅读
import moment from 'moment';
const handler = async (event, context) => …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 SAM 应用程序,该应用程序具有 lambda 函数,并以 API 网关作为事件源。API 端点是一种 POST 方法,需要在请求正文中提供一组参数。API Gateway 为我们提供了通过使用 AWS 控制台指定请求模型来验证请求正文的功能。
请参阅下面的 AWS 控制台选项屏幕截图:
我需要通过 SAM 模板设置类似的选项,并能够将模型与请求正文链接,但无法设置请求验证器选项,也无法找到任何文档或示例。
以下是我的 SAM 模板
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: SAM Template
Parameters:
Stage:
Type: String
Default: dev
Resources:
MyApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: My AWS Serverless API
StageName: !Ref Stage
Models:
ExchangeRate:
$schema: "http://json-schema.org/draft-04/schema#"
properties:
base:
type: string
target:
type: string
required:
- base
- target
title: User
type: object
ExchangeRateFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/exchange-rate/
Handler: …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda aws-api-gateway serverless aws-serverless
如何将 CloudWatch Lambda Insights 添加到无服务器配置?我不想手动执行此操作,因此我希望这是一个选项。
我添加了这样的跟踪:
tracing:
lambda: true
Run Code Online (Sandbox Code Playgroud)
但这只能启用 AWS X-ray 而不是其他选项。
我正在使用无服务器框架来部署 React Web 应用程序。我已经设置了用于部署的 CI/CD 管道。当执行无服务器模板时,我收到了几个弃用警告。
Serverless: Deprecation warning: Detected ".env" files. In the next major release variables from ".env" files will be automatically loaded into the serverless build process. Set "useDotenv: true" to adopt that behavior now.
More Info: https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES
Serverless: Deprecation warning: Variables resolver reports following resolution errors:
- Cannot resolve variable at "provider.profile": Value not found at "env" source
From a next major this will be communicated with a thrown error.
Set "variablesResolutionMode: 20210326" in your service …Run Code Online (Sandbox Code Playgroud)