我正在尝试构建一个使用aws获取所有Lightsial实例的小型vue.js应用程序。但是,我一直收到这个错误。
:8081/#/:1 Access to XMLHttpRequest at 'https://lightsail.us-west-2.amazonaws.com/' from origin 'http://localhost:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.这是我的vue组件脚本
import { AmplifyEventBus } from 'aws-amplify-vue'
import { components } from 'aws-amplify-vue'
import AWS from 'aws-sdk'
import Lightsail from 'aws-sdk/clients/lightsail'
import Auth from '@aws-amplify/auth';
import awsconfig from '../aws-exports';
export default {
components: {
AWS, Lightsail
},
data() {
return {
}
},
mounted() {
var myCredentials =
{
accessKeyId : '***************',
secretAccessKey : '****************'
}
AWS.config.update({
credentials: myCredentials, region: 'us-west-2'
});
var lightsail = new AWS.Lightsail();
lightsail.getInstances(function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
}
我还在此应用程序中使用aws-扩容-vue进行用户身份验证。
发布于 2019-03-10 07:03:22
发布于 2018-11-23 04:23:57
根据我的研究,这应该是一个CORS问题。这里有一个类似的线程,其中提到了一些解决方法。你能去看看它在你的场景中是否有效吗?
https://stackoverflow.com/questions/53440559
复制相似问题