gpt4 book ai didi

serverless-framework - 如何在 serverless.ts 文件中设置 provider.apiGateway.shouldStartNameWithService?

转载 作者:行者123 更新时间:2023-12-03 09:48:08 26 4
gpt4 key购买 nike

我正在使用新的无服务器 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

关于serverless-framework - 如何在 serverless.ts 文件中设置 provider.apiGateway.shouldStartNameWithService?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64670539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com