使用aws-apigatewayv2:
const AWS = require('aws-sdk');
const apigatewayv2 = new AWS.ApiGatewayV2();
const params = {
Name: 'MyApi', // API名称
ProtocolType: 'HTTP', // 使用的协议类型
Tags: { // 标记
'my-tag-1': 'tag-value-1',
'my-tag-2': 'tag-value-2'
}
};
apigatewayv2.createApi(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
使用aws-apigatewayv2-alpha:
const AWS = require('aws-sdk');
const apigatewayv2alpha = new AWS.ApiGatewayV2({
endpoint: 'https://apigateway.us-west-2.amazonaws.com', // 指定使用alpha版本的地址
region: 'us-west-2' // 地区
});
const params = {
Name: 'MyApi', // API名称
ProtocolType: 'HTTP', // 使用的协议类型
Tags: { // 标记
'my-tag-1': 'tag-value-1',
'my-tag-2': 'tag-value-2'
}
};
apigatewayv2alpha.createApi(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});