Tim*_*mer 7 serverless-framework
我正在使用新的无服务器 TypeScript monorepo 启动一个新项目!使用了aws-nodejs-typescript模板,它提供了一个serverless.ts配置文件。几周后,我现在在命令行上从 Serverless 收到以下很好的警告:
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from “{stage}-{service}” to “{service}-{stage}”.
Set “provider.apiGateway.shouldStartNameWithService” to “true” to adapt to the new behavior now.
More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Run Code Online (Sandbox Code Playgroud)
好的!看起来很棒,我喜欢新的命名。由于这是一个新项目,最好在我们发布任何内容之前立即应用新命名。但是,看起来 TypeScript 定义相当严格,似乎还不允许使用新变量:
Loading failed with: TSError: ? Unable to compile TypeScript:
serverless.ts(44,7): error TS2322: Type ‘{ minimumCompressionSize: number; shouldStartNameWithService: true; }’ is not assignable to type ‘ApiGateway’.
Object literal may only specify known properties, and ‘shouldStartNameWithService’ does not exist in type ‘ApiGateway’.
awsProvider.d.ts(51, 9): The expected type comes from property ‘apiGateway’ which is declared here on type ‘Provider’
Run Code Online (Sandbox Code Playgroud)
有没有办法在不将所有内容恢复为 YAML 的情况下设置新属性,这在这一点上会有些痛苦?
更新 1
非常感谢@NexGen 的指点!这是serverless.ts显示解决方案的最小(强调 TS!)。
import type { Serverless, ApiGateway } from 'serverless/aws';
const serverlessConfiguration: Serverless = {
service: {
name: 'foo',
},
frameworkVersion: '2',
custom: {
webpack: {
webpackConfig: './webpack.config.js',
packager: 'yarn',
includeModules: true,
},
alerts: {
stages: ['stage', 'prod'],
definitions: {
functionErrors: { treatMissingData: 'notBreaching' },
},
alarms: ['functionErrors'],
},
},
package: {
individually: true,
},
plugins: [
'serverless-webpack',
'serverless-jest-plugin',
'serverless-plugin-aws-alerts',
],
provider: {
name: 'aws',
runtime: 'nodejs12.x',
region: 'us-west-2',
stage: "${opt:stage, 'dev'}",
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
} as ApiGateway,
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
},
},
};
module.exports = serverlessConfiguration;
Run Code Online (Sandbox Code Playgroud)
小智 21
应用此更改非常简单,您需要做的就是将其添加到 serverless.yml 文件中。
provider:
apiGateway:
shouldStartNameWithService: true
Run Code Online (Sandbox Code Playgroud)
小智 6
provider: {
name: 'aws',
runtime: 'nodejs12.x',
apiGateway: {
shouldStartNameWithService: true
} as ApiGateway,
stage: 'dev'
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2812 次 |
| 最近记录: |