Hey Folks, I’m trying to debug a failed options re...
# help
h
Hey Folks, I’m trying to debug a failed options request and a failed post, both with 504. My endpoint method is lambda behind APIGateway and already added in an options response and originally it gave a 200, but I didn’t realize it was supposed to return 204. I’m using {proxy+}, I can see the OPTIONS going through and returning and I can hit it with postman and see it too. But the browser (1st screenshot) isn’t happy with my response, and it’s giving me a timeout on the POST. I don’t know if I don’t have the right format or the right headers or what; I’ve tried a ton of amalgamations. And I tried to do something like on REST, but it doesn’t have those options because it’s HttpAPI, and also have the CORS setup on the API side of things. Below 2nd screenshot it’s not returning anything. I made a custom header with “allow” and got it to add “allow: OPTIONS, GET, HEAD, POST”, but it still didn’t work on the browser. So I’m missing something fundamental here, Normally one doesn’t handle the OPTIONS method at all but in {proxy+}, everything gets forwarded and HttpApi works differently than REST. In theory, my curl response should return something like:
Copy code
OPTIONS /resources/post-here/ HTTP/1.1
Host: bar.example
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Connection: keep-alive
Origin: <https://foo.example>
Access-Control-Request-Method: POST
Access-Control-Request-Headers: X-PINGOTHER, Content-Type
Any help on this would mean a lot for me. Great Thanks!
Hey Haider have you tried tracing your Lambda with an APM or so?
o
If it’s working in postman but not in browser, it’s probably a CORS issue. Maybe you’re not returning all the headers you need to in
Access-Control-Request-Headers
f
@Haider Abbas Can I see how you are configuring CORS in ur Api?
Thanks @Haider Abbas can I see the cors definition in the
Api
construct?
h
API Construct
Copy code
'use strict';

import AWS from 'aws-sdk';
import { DB, getDatabasePassword } from './db-handler';
import { IClientDetailsRow } from './interfaces/client-details-row.interface';
import { internalErrorResponse, successResponse } from './response';

const DB_PORT = '3306';
const DB_CHARSET = 'utf8mb4';
const CLUSTER_CREATE_THRESHOLD = '15';
const INSTANCE_CREATE_THRESHOLD = '45';
const S3_POLICY_WAIT_THRESHOLD = '15';
const JOB_SPIN_UP_NEW_TENANT_DEF_NAME = 'admin-tasks';
const JOB_SPIN_UP_NEW_TENANT_Q_NAME = 'admin-tasks';
const AWS_ACCOUNT_NUMBER = process.env.AWS_ACCOUNT_NUMBER;

const submitHandler = async (countkey: string, context, callback) => {
    console.log('IN submitHandler');
    const arnList = (context.invokedFunctionArn).split(':');
    const region: string = arnList[3];
    console.log(`arnList: ${arnList}; region: ${region}`);
    return await getClientDetails(countkey)
        .then(async (clientDetails: IClientDetailsRow) => {
            return await createEcsClusterIfItDoesNotExist(region, clientDetails,
                callback);
        })
        .catch((error) => {
            console.log(error);
            return callback('ERROR: Get client details call failed', internalErrorResponse());
        });
};
index.ts
Copy code
import { customerSetup, submitJob } from './handler';
import {
    healthCheckResponse,
    internalErrorResponse,
    optionsResponse,
    routeNotFoundResponse
} from './response';

export const lambdaHandler = async (event: any, context: any, callback: any) => {
    console.log(event);
    return await getRoute(event, context, callback);
};

const getRoute = async (event: any, context: any, callback: any) => {
    try {
        console.log('IN getRoute');
        const requestVerb = `${event['requestContext']['http']['method']}`;
        console.log(`requestVerb ${requestVerb}`);
        if (requestVerb === 'OPTIONS') {
            console.log('IN OPTIONS response');
            console.log(optionsResponse());
            return callback(null, optionsResponse());
        }
        const pathParameters = `${event['pathParameters']['proxy']}`.toLowerCase();
        const path = `${requestVerb} ${pathParameters}`;
        console.log(`path: ${path}`);
        switch (path) {
            case 'POST submitjob':
                console.log('IN submitJob case');
                return await submitJob(event, context, callback);
            case 'POST customer_setup':
                return await customerSetup(event, context, callback);
            // case 'POST deleteCustomer':
            //     // TODO: Get proper object off of event to make this work
            //     // Was not wired up before, so need to reattach
            //     // And this needs to be protected/authenticated.
            //     const companyDomainName = event.message.rds_host;
            //     return await deleteCluster('us-east-1', companyName, callback);
            case 'GET healthcheck':
                return callback(null, healthCheckResponse());
            default:
                return callback(null, routeNotFoundResponse());
        }
    } catch (error) {
        console.log(error);
        return callback('ERROR: Get Route Failed.', internalErrorResponse());
    }
};
Hey @Frank! Did you get a chance to have a look ^ Great Thanks Dear!
j
@Haider Abbas just checking here, are you still having this issue?
h
Thanks @Jay for asking. It’s resolved now.