在该serverless.yml文件中,您可以指定要与已部署API中的函数一起使用的API密钥的名称.列出API密钥名称,然后将要保护的方法标记为私有.例如:
provider:
name: aws
runtime: nodejs4.3
cfLogs: true
apiKeys:
- MyAPIKey
Run Code Online (Sandbox Code Playgroud)
部署后,框架会生成API密钥并将其分配给函数.即使环境中已存在具有相同名称的密钥,它也会生成密钥.
有没有办法指定现有的API密钥,而不是让框架生成它?我们真的希望继续生成与部署分开的密钥.
我使用无服务器框架实现了AWS Lambda功能.Lambda函数使用RDS和MongoDB.MongoDB端点运行大约500ms,但RDS运行12秒(冷启动)和~3秒(热启动).
注意:我在此端点中使用Sequelize.
如何加速我的RDS Lambda端点?
amazon-rds node.js aws-lambda serverless-framework serverless-architecture
我正在使用无服务器框架来构建REST API。我已经达到了200个限制堆栈大小,并了解了多种绕过它的方法。最常见的方法是以“微服务方式”拆分堆栈,其中每个堆栈都处理一组有意义的特定资源。
由于无服务器的工作方式,所有这些服务都会为其自身创建一个新的api网关,然后,如本博文中所述,可以在它们之间设置一个共享域,以便可以通过相同的基本url访问所有端点。
即使这是一个有效的解决方案,我仍然非常希望能够使用在不同堆栈之间共享的单个API网关资源,因此我不必预先决定api的不同组件之间的关注点分离。这可能吗?
我使用无服务器框架将python函数部署到aws lambda上
我的配置文件serverless.yml如下
frameworkVersion: "=1.27.3"
service: recipes
provider:
name: aws
endpointType: REGIONAL
runtime: python3.6
stage: dev
region: eu-central-1
memorySize: 512
deploymentBucket:
name: dfki-meta
versionFunctions: false
stackTags:
Project: DFKIAPP
# Allows updates to all resources except deleting/replacing EC2 instances
stackPolicy:
- Effect: Allow
Principal: "*"
Action: "Update:*"
Resource: "*"
- Effect: Deny
Principal: "*"
Action:
- Update: Replace
- Update: Delete
Resource: "*"
Condition:
StringEquals:
ResourceType:
- AWS::EC2::Instance
# Access to RDS and S3 Bucket
iamRoleStatements:
- Effect: "Allow"
Action: "s3:ListBucket" …Run Code Online (Sandbox Code Playgroud) 我正在使用包上传压缩文件
frameworkVersion: "=1.27.3"
service: recipes
provider:
name: aws
endpointType: REGIONAL
runtime: python3.6
stage: dev
region: eu-central-1
memorySize: 512
deploymentBucket:
name: dfki-meta
versionFunctions: false
stackTags:
Project: DFKIAPP
# Allows updates to all resources except deleting/replacing EC2 instances
stackPolicy:
- Effect: Allow
Principal: "*"
Action: "Update:*"
Resource: "*"
- Effect: Deny
Principal: "*"
Action:
- Update: Replace
- Update: Delete
Resource: "*"
Condition:
StringEquals:
ResourceType:
- AWS::EC2::Instance
# Access to RDS and S3 Bucket
iamRoleStatements:
- Effect: "Allow"
Action: "s3:ListBucket"
Resource: "*" …Run Code Online (Sandbox Code Playgroud) 我有一个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配置吗?
我正在寻找一种在基于node.js的aws lambda函数中跟踪axios http请求的方法。我发现了一种在AWS官方文档https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-httpclients.html上跟踪HTTP请求的方法
var AWSXRay = require('aws-xray-sdk');
var http = AWSXRay.captureHTTPs(require('http'));
Run Code Online (Sandbox Code Playgroud)
但是我没有找到任何有关axios请求跟踪的文档或博客。我也尝试过此代码,但无法正常工作。
import AWSXRay from 'aws-xray-sdk';
AWSXRay.captureHTTPsGlobal("../../common/http/HttpClient");
import { HttpClient } from "../../common/http/HttpClient";
Run Code Online (Sandbox Code Playgroud)
在这方面我需要帮助。谢谢!
我在用着:
我正在连接到数据库,就像 github 中描述的那样,
const connection = await createConnection({
type: 'aurora-data-api-pg',
database: 'test-db',
secretArn: 'arn:aws:secretsmanager:eu-west-1:537011205135:secret:xxxxxx/xxxxxx/xxxxxx',
resourceArn: 'arn:aws:rds:eu-west-1:xxxxx:xxxxxx:xxxxxx',
region: 'eu-west-1'
})
Run Code Online (Sandbox Code Playgroud)
这就是我在 Lambda 函数中使用它的方式
export const testConfiguration: APIGatewayProxyHandler = async (event, _context) => {
let response;
try {
const connectionOptions: ConnectionOptions = await getConnectionOptions();
const connection = await createConnection({
...connectionOptions,
entities,
});
const userRepository = connection.getRepository(User);
const users = await userRepository.find();
response = {
statusCode: 200,
body: JSON.stringify({ users }),
}; …Run Code Online (Sandbox Code Playgroud) aws-lambda serverless-framework typeorm aws-aurora-serverless
我有一个基于 Typescript 的 Lambda 函数,可以正常编译,tsc但当我尝试通过无服务器部署时,Typescript 复杂性失败并出现以下错误:
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Warning: "rootDir" from local tsconfig.json is overriden
Cannot locate handler - account. not found
Error --------------------------------------------------
Error: Typescript compilation failed. Please ensure handlers exists with ext .ts or .js
at /Users/bob/Development/service-account/node_modules/serverless-plugin-typescript/src/typescript.ts:69:13
Run Code Online (Sandbox Code Playgroud)
相关的代码块account.ts是:
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Warning: "rootDir" from local …Run Code Online (Sandbox Code Playgroud) 因此,作为借口,我几乎不知道该怎么办。我研究了大约两个小时,通常我会继续下去,但我发现的信息都没有用。我怀疑这与 YAML (serverless.yml) 文件有关,但我不确定。我对该文件进行了多次更新,因此我将发布初始代码和当前代码,尽管没有任何区别。该代码在开发中完美运行,但在生产中会引发错误。您可以查看https://www.evote.space来复制此内容。
当前的
myNextApplication:
service: myService
component: "@sls-next/serverless-component@1.18.0"
provider:
name: aws
runtime: nodejs12.x
stage: dev
profile: evote
iam:
role: rolenamegoesherebutnotonstackoverflow
inputs:
domain: "evote.space"
functions:
createuser:
handler: data.createuser
readTable:
handler: data.readTable
resources:
Resources:
usersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Users
AttributeDefinitions:
- AttributeName: userHash
AttributeType: N
KeySchema:
- AttributeName: userHash
KeyType: HASH
votersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Voters
AttributeDefinitions:
- AttributeName: voterHash
AttributeType: N
KeySchema:
- AttributeName: voterHash
KeyType: HASH
electionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Elections
AttributeDefinitions:
- …Run Code Online (Sandbox Code Playgroud) amazon-cloudfront aws-lambda serverless-framework serverless
aws-lambda ×6
serverless ×4
node.js ×2
amazon-rds ×1
aws-xray ×1
docker ×1
typeorm ×1
typescript ×1