私は、serverlessを使用してセットアップしたラムダ関数に、anglejsアプリケーションからhttpリクエストを実行しようとしています。ここでサーバレスAWSラムダCORSエラー
は私のserverless.yaml機能は
functions:
createcustomer:
handler: handler.createcustomer
events:
- http: post /createcustomer
cors: true
である私はしかし、私はこれを取得しておく。この
app.factory('MyFactory', ['$http', function($http) {
return {
CreateCustomer: function(customer) {$http.post('<apipath>/createcustomer', {customer:customer})}
}
}]);
のようにそれを呼び出す私のAngularJSアプリから
module.exports.createcustomer = (event, context, callback) => {
let customer = JSON.parse(event.body).customer;
service.create(customer, function(result) {
let response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
body: JSON.stringify({
result: 'Created Customer Successfully',
message: 'The account has been created!',
type: 'success',
customer: result
})
};
callback(null, response);
});
};
お客様関数を作成エラー:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:5000 ' is therefore not allowed access. The response had HTTP status code 403.
POSTメソッドでAPIゲートウェイでCORSを有効にしようとしましたが、結果が変更されませんでした。
は私もまだYAMLファイルを明示的functions:
createcustomer:
handler: handler.createcustomer
events:
- http: post /createcustomer
cors:
origin: '*'
運でCORSを設定しようとしました。
私がここで間違っていることを誰もが知っていますか?
奇妙なことは、私がPostManを使ってうまく動作するようにすることができるということですが、私のアプリを通してそれを試してみると、壊れます。
おかげ
UPDATE
私はserverless deploy
を行うと、それは上の写真のようにAWSに表示し、私が言ったようにメソッドは、この
のように見えます以前は、API Gatewayコンソールから直接CORSを有効にしようとしましたが、メソッドを呼び出そうとすると、違いはありませんでした。
ラムダ応答にAccess-Control-Allow-Headersヘッダーを追加してみます。 –
@KaustubhKhareは、まだ運を試していません。 – DevShadow
投稿した内容に基づいて表示されます。私はAPIゲートウェイコンソールとラムダコンソールが本当に反映され、正しく展開されているかどうかを確認するためにコンソールをチェックします。 – dashmug