我无法在浏览器中使用 AWS javascript SDK V3 来使用 Gamelift,我首先使用 javascript v3 中的 aws gamelift 创建了一个 nodejs 作为一个好孩子,我按照他们的说明使用 webpack 打包它。
index.js
import * as AWS_S3 from "@aws-sdk/client-s3";
import * as AWS from "@aws-sdk/client-gamelift";
export async function createGameLiftObject()
{
var gamelift = new AWS.GameLiftClient(
{endpoint : 'http://localhost:9080',
accessKeyId :'abcde',
secretAccessKey:'abcde',
region:'us-west-2'});
const input = {
FleetId : 'fleet-123d'
};
const command = new AWS.DescribeGameSessionDetailsCommand(input);
const response = await gamelift.send(command);
console.log(response);
}
用 webpack 打包
webpack.config.js
// Import path for resolving file paths
var path = require("path");
module.exports = {
// Specify the entry point for our app.
entry: [path.join(__dirname, "index.js")],
// Specify the output file containing our bundled code.
output: {
path: __dirname,
filename: 'bundle.js',
library: 'myLibrary'
},
optimization: {
minimize: false
},
// Enable WebPack to use the 'path' package.
resolve:{
fallback: { path: require.resolve("path-browserify")}
}
/**
* In Webpack version v2.0.0 and earlier, you must tell
* webpack how to use "json-loader" to load 'json' files.
* To do this Enter 'npm --save-dev install json-loader' at the
* command line to install the "json-loader' package, and include the
* following entry in your webpack.config.js.
* module: {
rules: [{test: /\.json$/, use: use: "json-loader"}]
}
**/
};
它生成了 bundle.js,我将它加载到基于浏览器的 HTML 文件中,只是为了测试它是否有效
<html>
<head>
<title>Templated client</title>
<script src="./bundle.js"></script> <!--<script type="module" lang="javascript">-->
<script>
var gamelift = myLibrary.createGameLiftObject();
</script>
</head>
<body>
</body>
</html>
我收到错误
Uncaught (in promise) Error: Credential is missing
at SignatureV4.tslib_es6_assign.credentialDefaultProvider [as credentialProvider] (uint32ArrayFrom.ts:16:2)
at SignatureV4.<anonymous> (uint32ArrayFrom.ts:16:2)
at step (uint32ArrayFrom.ts:16:2)
at Object.next (uint32ArrayFrom.ts:16:2)
at uint32ArrayFrom.ts:16:2
at new Promise (<anonymous>)
at tslib_es6_awaiter (uint32ArrayFrom.ts:16:2)
at SignatureV4.signRequest (uint32ArrayFrom.ts:16:2)
at SignatureV4.<anonymous> (uint32ArrayFrom.ts:16:2)
at step (uint32ArrayFrom.ts:16:2)
问题是,如果我将它作为独立的 nodejs 运行,它只适用于相同的调用序列。我错过了什么
上下文:我使用本地测试网络 GameLiftLocal-1.0.5,它是 GameLift_06_03_2021 的一部分
SDK坏了吗?
更新:我将实现更改为使用这样的凭据
const credentials = {
accessKeyId :'abcde',
secretAccessKey:'abcde',
};
const gamelift = new AWS.GameLiftClient({
endpoint : 'http://localhost:9080',
credentials,
region:'us-west-2'
});
现在错误是
Failed to load resource: net::ERR_EMPTY_RESPONSE
uint32ArrayFrom.ts:16 TypeError: Failed to fetch
at FetchHttpHandler.<anonymous> (bundle.js:5442:29)
at step (bundle.js:2204:23)
at Object.next (bundle.js:2185:53)
at fulfilled (bundle.js:2175:58)
我开始认为 AWS javascript SDK V3 特别适用于 gamelift 不起作用或不支持浏览器。