简体   繁体   中英

Angular 2 Accessing AWS API Gateway

Baffled on what the issue is here. I am trying to access a Lambda function on AWS through my Angular 2 application. Cross origin is enabled in AWS. In Chrome I am getting 200 responses in the Network tab.

Preflight Options Request 飞行前选项请求

GET Request 在此处输入图片说明

The console however shows a 403 在此处输入图片说明

Here is the Angular code

import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

getAWS(): Observable<any> {
    return this.http.get('https://9rw0xrw730.execute-api.us-east-1.amazonaws.com/default/...', {
        headers: {
        'x-api-key': 'myapi key'
        }
      }
    );
  }

Solved...

I had to explicitly add it to the Lambda Function itself. I did add it to the API Gateway which got me to the point above. But still didn't have the header on the actual response.

Here is the Lambda code: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM