如何解决如何在serverless.ts文件中设置provider.apiGateway.shouldStartNameWithService?
我正在使用新的无服务器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
好!看起来很棒,我喜欢新的命名方式。由于这是一个新项目,因此最好在发布任何内容之前立即应用新命名。但是,看起来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’
是否可以在不将所有内容恢复为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;
解决方法
应用此更改非常简单,只需将其添加到serverless.yml文件中即可。
provider:
apiGateway:
shouldStartNameWithService: true
,
provider: {
name: 'aws',runtime: 'nodejs12.x',apiGateway: {
shouldStartNameWithService: true
} as ApiGateway,stage: 'dev'
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。