在AWS Lambda的Node.js代码中使用AWS SDK for JavaScript将Api Gateway阶段名称更改为指定值。
以下是示例代码:
const AWS = require('aws-sdk'); AWS.config.update({ region: 'your-region' });
const apigateway = new AWS.APIGateway();
const restApiId = 'your-rest-api-id'; const stageName = 'new-stage-name';
const params = { restApiId, stageName, patchOperations: [ { op: 'replace', path: '/stageName', value: stageName, }, ], };
apigateway.updateStage(params, (err, data) => { if (err) { console.log(err, err.stack); } else { console.log(data); } });
请记得自行更改“your-region”和“your-rest-api-id”。详细了解API Gateway的阶段更改操作,请参阅AWS文档。
下一篇:API网关选项方法抛出403错误