Active record association in rails 4/5 - ruby-on-rails-4

I have the following four models and I need help with how to associate the projects model to the timesheet and task model. The models I have are as follows:
User
Timesheet => has_many :tasks
Project => beloings_to :task
Project => has_many :tasks
Task => belongs_to :timesheet
Task=> belongs_to :project
When I execute the following association I get a response as shown below;
User.find(1).time_sheets.find(6).tasks
[
#<Task:0x00007fbdf5419780 id: 15, description: "Fixed the mat issue", task_date: "May 17, 2021", hours_worked: 3, project_id:
2, created_at: Mon, 17 May 2021 16:57:28 UTC +00:00, updated_at:
Mon, 17 May 2021 16:57:28 UTC +00:00, time_sheet_id: 6>,
#<Task:0x00007fbdf54194b0 id: 16, description: "Built IOS and Android module", task_date: "May 17, 2021", hours_worked: 3,
project_id: 5, created_at: Mon, 17 May 2021 23:41:00 UTC +00:00,
updated_at: Mon, 17 May 2021 23:41:00 UTC +00:00, time_sheet_id: 6>,
]
How do I associate the project model to the response and be able to be able to get the project_name in the result? Thanks for the help.

Related

Issue Running Google Lighthouse in Docker Container

I'm attempting to run lighthouse in a Docker container for eventual deployment to AWS Lambda (using its new docker image lambda deployments). However I'm getting an error that I can't seem to understand.
The following is my dockerfile
FROM amazon/aws-lambda-nodejs:12
ENV AWS_LAMBDA_FUNCTION_MEMORY_SIZE=10240
RUN curl https://intoli.com/install-google-chrome.sh | bash
copy package.json .
RUN npm install
COPY app.js .
CMD ["app.handler"]
The following is my app.js
const chromeLauncher = require("chrome-launcher");
const lighthouse = require("lighthouse");
exports.handler = async (event) => {
const chrome = await chromeLauncher.launch({
logLevel: "info",
chromeFlags: [
"--headless",
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
"--single-process",
],
});
const results = await lighthouse("https://example.com", {
port: chrome.port,
disableStorageReset: true,
onlyCategories: ["performance"],
logLevel: "info",
});
return {
statusCode: 200,
results,
};
};
and the following is the log output. It seems to be able to connect to lighthouse but then is hanging on the first command it sends/
START RequestId: c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7 Version: $LATEST
Sun, 24 Jan 2021 16:00:56 GMT ChromeLauncher Waiting for browser.
Sun, 24 Jan 2021 16:00:56 GMT ChromeLauncher Waiting for browser...
Sun, 24 Jan 2021 16:00:57 GMT ChromeLauncher Waiting for browser.....
Sun, 24 Jan 2021 16:00:57 GMT ChromeLauncher Waiting for browser.....✓
Sun, 24 Jan 2021 16:00:58 GMT status Connecting to browser
Sun, 24 Jan 2021 16:00:58 GMT status Resetting state with about:blank
Sun, 24 Jan 2021 16:01:28 GMT status Disconnecting from browser...
2021-01-24T16:01:28.172Z c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7 ERROR Invoke Error {"errorType":"LHError","errorMessage":"PROTOCOL_TIMEOUT","code":"PROTOCOL_TIMEOUT","name":"LHError","friendlyMessage":"Waiting for DevTools protocol response has exceeded the allotted time. (Method: Network.enable)","lhrRuntimeError":true,"protocolMethod":"Network.enable","stack":["LHError: PROTOCOL_TIMEOUT"," at Timeout._onTimeout (/var/task/node_modules/lighthouse/lighthouse-core/gather/driver.js:409:21)"," at listOnTimeout (internal/timers.js:554:17)"," at processTimers (internal/timers.js:497:7)"]}
END RequestId: c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7
REPORT RequestId: c9d7a07b-a5e2-4d03-8bf5-d0b5d248e3e7 Init Duration: 3.53 ms Duration: 33422.31 ms Billed Duration: 33500 ms Memory Size: 2010240 MB Max Memory Used: 2010240 MB
To run on AWS Function Lambda you should use
const chromium = require("chrome-aws-lambda");
const chrome = await chromium.puppeteer.launch({
args: [
...chromium.args,
"--disable-dev-shm-usage",
"--remote-debugging-port=9222",
],
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const options = {
logLevel: "info",
output: "html",
onlyCategories: ["performance"],
preset: "mobile",
port: 9222,
};
const runnerResult = await lighthouse(`${body.url}`, options);
But, I'm facing errors in the performance category, there is no way to make it works, All the others categories work fine.

aws api gateway return "internal server error" if response body is not stringify

I have the following handler code:
export default function handler(lambda) {
return function (event, context) {
return Promise.resolve()
// Run the Lambda
.then(() => lambda(event, context))
// On success
.then((responseBody) => [200, responseBody])
// On failure
.catch((e) => {
return [500, { error: e.message }];
})
// Return HTTP response
.then(([statusCode, body]) => ({
statusCode,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
},
body: JSON.stringify(body),
}))
// On failure
.catch((e) => {
return [500, { error: e.message }];
});
};
}
whenever I created a new Lambda function, I import this code and write the code base on it, like this:
import handler from "../libs/handler-lib";
export const main = handler(async (event, context) => {
"my code"
}
which works like a charm, but the problem is, I need to access the response body in aws stepfunctions to determine which function to execute next, so I change
body: JSON.stringify(body), to body: body,
Then every function works only in the lambda function console but fails if the lambda is triggered by the aws api gateway.
I think I am missing something obvious here but I cant tell.
Thanks in advance.
here is the full api gateway log:
Execution log for request 8677ed2f-5e9e-4913-8fe9-f1d2f9b2ac12
Sun Nov 15 16:00:51 UTC 2020 : Starting execution for request: 8677ed2f-5e9e-4913-8fe9-f1d2f9b2ac12
Sun Nov 15 16:00:51 UTC 2020 : HTTP Method: GET, Resource Path: /latest-patch-json-data
Sun Nov 15 16:00:51 UTC 2020 : Method request path: {}
Sun Nov 15 16:00:51 UTC 2020 : Method request query string: {}
Sun Nov 15 16:00:51 UTC 2020 : Method request headers: {}
Sun Nov 15 16:00:51 UTC 2020 : Method request body before transformations:
Sun Nov 15 16:00:51 UTC 2020 : Endpoint request URI: https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxx:function:tactics-api-dev-getLatestPatchJsonData/invocations
Sun Nov 15 16:00:51 UTC 2020 : Endpoint request headers: {x-amzn-lambda-integration-tag=8677ed2f-5e9e-4913-xxxxxxxx, Authorization=*****************************************************************************************************************************************************************************************************************************************************************************************************************************7603ee, X-Amz-Date=20201115T160051Z, x-amzn-apigateway-api-id=f8brp6pbai, X-Amz-Source-Arn=arn:aws:execute-api:ap-northeast-1:296545255814:f8brp6pbai/test-invoke-stage/GET/latest-patch-json-data, Accept=application/json, User-Agent=AmazonAPIGateway_f8brp6pbai, X-Amz-Security-Token=IQoJb3JpZ2luX2VjEIf//////////wEaDmFwLW5vcnRoZWFzdC0xIkgwRgIhALgraV2CJa+NzHo/sSqH4MgbwVveHpse1s9DNkN5B/5JAiEAnghcO0tmUqhMhB+PxZ/lWbApusJKxJSM1zoIAtqFHycqxwMI8P//////////ARABGgw5NjkyMzY4NTQ2MjYiDI4NEh+wCOuUEqvN/iqbA+UIa11YzWxKIHWZ5hBsK7z/zSPD7Jz9S/3SH3L1M/IpjgbFC3g/y7B+tDj1lZ5nuzXbqlpg092hCt5JR1otT7w45xu0yQdZwcVPT9LV [TRUNCATED]
Sun Nov 15 16:00:51 UTC 2020 : Endpoint request body after transformations: {"resource":"/latest-patch-json-data","path":"/latest-patch-json-data","httpMethod":"GET","headers":null,"multiValueHeaders":null,"queryStringParameters":null,"multiValueQueryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"resourceId":"b31s1i","resourcePath":"/latest-patch-json-data","httpMethod":"GET","extendedRequestId":"WDmMCE8mtjMFqQg=","requestTime":"15/Nov/2020:16:00:51 +0000","path":"/latest-patch-json-data","accountId":"296545255814","protocol":"HTTP/1.1","stage":"test-invoke-stage","domainPrefix":"testPrefix","requestTimeEpoch":1605456051327,"requestId":"8677ed2f-5e9e-4913-8fe9-f1d2f9b2ac12","identity":{"cognitoIdentityPoolId":null,"cognitoIdentityId":null,"apiKey":"test-invoke-api-key","principalOrgId":null,"cognitoAuthenticationType":null,"userArn":"arn:aws:iam::296545255814:root","apiKeyId":"test-invoke-api-key-id","userAgent":"aws-internal/3 aws-sdk-java/1.11.864 Linux/4.9.217-0.3.ac.206.84.332.metal1.x86_64 OpenJD [TRUNCATED]
Sun Nov 15 16:00:51 UTC 2020 : Sending request to https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:tactics-api-dev-getLatestPatchJsonData/invocations
Sun Nov 15 16:00:52 UTC 2020 : Received response. Status: 200, Integration latency: 805 ms
Sun Nov 15 16:00:52 UTC 2020 : Endpoint response headers: {Date=Sun, 15 Nov 2020 16:00:52 GMT, Content-Type=application/json, Content-Length=284, Connection=keep-alive, x-amzn-RequestId=753115e8-0264-4517-9a2a-f67f045b7011, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5fb150b3-b7a44f36147dc1a10b321a85;sampled=0}
Sun Nov 15 16:00:52 UTC 2020 : Endpoint response body before transformations: {"statusCode":200,"headers":{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":true},"body":{"latestPatchVersion":"10.23","message":"PDH is up-to-date, PDH record: cc01f980-273a-11eb-b79f-676006f2be2a lastCheck time: 2020-11-15T16:00:51.996Z","type":"skip update"}}
Sun Nov 15 16:00:52 UTC 2020 : Execution failed due to configuration error: Malformed Lambda proxy response
Sun Nov 15 16:00:52 UTC 2020 : Method completed with status: 502
For lambda proxy, the lambda return object has to be of this shape :
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headerName": "headerValue", ... },
"body": "..."
}
That means, the body needs to be a string, not an object.

API gateway and DynamoDB integration - SerializationException

I have setup an API endpoint integration to DynamoDB.
I want to query a table using query string parameter as query filter.
Unfortunatley I ended up getting error:
Method response body after transformations: {"__type":"com.amazon.coral.service#SerializationException"}
with no clue what is the root cause.
To do the stated above I have taken the following steps:
1) Setup a get method in API gateway
2) In the Method Request I added a parameter to URL Query String Parameters
3) In the integration request I added the same parameter from step 2 in URL Query String Parameters
4)In DynamoDB table I decalred a new index for the column that I'd like to query
5)In body mapping template:
{
"TableName": "tjusers",
"IndexName" "badge-index",
"KeyConditionExpression": "badge = :v1",
"ExpressionAttributeValues": {
":v1": {
"S": "$input.params('badge')"
}
}
}
THe exception:
xecution log for request f0081606-b521-11e8-adb2-cd8092221b33
Mon Sep 10 17:50:00 UTC 2018 : Starting execution for request: f0081606-b521-11e8-adb2-cd8092221b33
Mon Sep 10 17:50:00 UTC 2018 : HTTP Method: GET, Resource Path: /db/users
Mon Sep 10 17:50:00 UTC 2018 : Method request path: {}
Mon Sep 10 17:50:00 UTC 2018 : Method request query string: {badge=18323}
Mon Sep 10 17:50:00 UTC 2018 : Method request headers: {}
Mon Sep 10 17:50:00 UTC 2018 : Method request body before transformations:
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request URI: https://dynamodb.us-west-2.amazonaws.com/?Action=Query&badge=11111
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request headers: {Authorization=****************************************************************************************************************************************************************************************************************************************************************************************feb2ac, X-Amz-Date=20180910T175000Z, x-amzn-apigateway-api-id=53zgcztitj, Accept=application/json, User-Agent=AmazonAPIGateway_53zgcztitj, X-Amz-Security-Token=AgoGb3JpZ2l....
Mon Sep 10 17:50:00 UTC 2018 : Endpoint request body after transformations: {
"TableName": "tjusers",
"IndexName" "badge-index",
"KeyConditionExpression": "badge = :v1",
"ExpressionAttributeValues": {
":v1": {
"S": "11111"
}
}
}
Mon Sep 10 17:50:00 UTC 2018 : Sending request to https://dynamodb.us-west-2.amazonaws.com/?Action=Query&badge=18323
Mon Sep 10 17:50:00 UTC 2018 : Received response. Integration latency: 11 ms
Mon Sep 10 17:50:00 UTC 2018 : Endpoint response body before transformations: {"__type":"com.amazon.coral.service#SerializationException"}
Mon Sep 10 17:50:00 UTC 2018 : Endpoint response headers: {Server=Server, Date=Mon, 10 Sep 2018 17:49:59 GMT, Content-Type=application/x-amz-json-1.0, Content-Length=60, Connection=keep-alive, x-amzn-RequestId=ODMJ814D1GBN875T6MTR7BUHGVVV4KQNSO5AEMVJF66Q9ASUAAJG, x-amz-crc32=3948637019}
Mon Sep 10 17:50:00 UTC 2018 : Method response body after transformations: {"__type":"com.amazon.coral.service#SerializationException"}
Mon Sep 10 17:50:00 UTC 2018 : Method response headers: {X-Amzn-Trace-Id=Root=1-5b96aec8-addec09261723342f53a179f, Content-Type=application/json}
Mon Sep 10 17:50:00 UTC 2018 : Successfully completed execution
Mon Sep 10 17:50:00 UTC 2018 : Method completed with status: 200
You are missing : after "IndexName", that cause SerializationException
What is the schema of your tjusers DynamoDB Table?
In particular, what is the datatype of badge? If it is Number, for example, you need to be using "N" instead of "S".
(In general, here is a recent new tutorial that meets your requirements and has more details/screenshots than I've seen in others: https://medium.com/#likhita507/using-api-gateway-to-get-data-from-dynamo-db-using-without-using-aws-lambda-e51434a4f5a0)

AWS API Gateway Cannot GET / when function sleeped for long time

My current stack is AWS API Gateway --> AWS Lambda --> swagger-node + swagger-express-mw + aws-serverless-express.
So my Swagger API is hosted as one node.js Lambda Function and Invoked with aws_proxy from API Gateway. This works quite good. The only thing is that when the function sleeped for too long (cold start?) I get a Cannot GET / as Output from every URL I am calling first. From 2nd Request on, it runs very fast. Any ideas on that?
I don't think that it comes from API Gateway Integration Timeout as that are 30 seconds. The slowest invocation time of the function directly via lambda is around 2,5s and when it is called more often it is normally not more than 150ms. I also increased the Time of Lambda Timeout for that function to 10s so from there should also not come an error.
Logs from Test Request via API Gateway first Invocation
Response Body
Cannot GET /hello
Response Headers
{
"x-powered-by": "Express",
"x-content-type-options": "nosniff",
"content-type": "text/html; charset=utf-8",
"content-length": "18",
"date": "Sun, 19 Feb 2017 15:00:11 GMT",
"connection": "close",
"X-Amzn-Trace-Id": "<TRACE-ID>"
}
Logs
Execution log for request test-request
Sun Feb 19 15:00:07 UTC 2017 : Starting execution for request: test-invoke-request
Sun Feb 19 15:00:07 UTC 2017 : HTTP Method: GET, Resource Path: /hello
Sun Feb 19 15:00:07 UTC 2017 : Method request path: {}
Sun Feb 19 15:00:07 UTC 2017 : Method request query string: {}
Sun Feb 19 15:00:07 UTC 2017 : Method request headers: {}
Sun Feb 19 15:00:07 UTC 2017 : Method request body before transformations:
Sun Feb 19 15:00:07 UTC 2017 : Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:<ACCOUNT-ID>:function:api/invocations
Sun Feb 19 15:00:07 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=**************************************************************************************************************************************************************************************************************************************************************************************************************************4b0637, X-Amz-Date=20170219T150007Z, x-amzn-apigateway-api-id=965h04axki, Accept=application/json, User-Agent=AmazonAPIGateway_965h04axki, X-Amz-Security-Token=<SECURITY-TOKEN>
Sun Feb 19 15:00:07 UTC 2017 : Endpoint request body after transformations: {"resource":"/hello","path":"/hello","httpMethod":"GET","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"<ACCOUNT-ID>","resourceId":"ll6gw8","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"<ACCOUNT-ID>","cognitoIdentityId":null,"caller":"<ACCOUNT-ID>","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"<ACCESS-ID>","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::<ACCOUNT-ID>:root","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_102)","user":"<ACCOUNT-ID>"},"resourcePath":"/hello","httpMethod":"GET","apiId":"965h04axki"},"body":null,"isBase64Encoded":false}
Sun Feb 19 15:00:11 UTC 2017 : Endpoint response body before transformations: {"statusCode":404,"body":"Cannot GET /hello\n","headers":{"x-powered-by":"Express","x-content-type-options":"nosniff","content-type":"text/html; charset=utf-8","content-length":"18","date":"Sun, 19 Feb 2017 15:00:11 GMT","connection":"close"},"isBase64Encoded":false}
Sun Feb 19 15:00:11 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=19f8554e-f6b4-11e6-8184-d3ccf0ccf643, Connection=keep-alive, Content-Length=267, Date=Sun, 19 Feb 2017 15:00:11 GMT, Content-Type=application/json}
Sun Feb 19 15:00:11 UTC 2017 : Method response body after transformations: Cannot GET /hello
Sun Feb 19 15:00:11 UTC 2017 : Method response headers: {x-powered-by=Express, x-content-type-options=nosniff, content-type=text/html; charset=utf-8, content-length=18, date=Sun, 19 Feb 2017 15:00:11 GMT, connection=close, X-Amzn-Trace-Id=Root=1-58a9b2f7-91fc7371e41d6ae9c2fbf64d}
Sun Feb 19 15:00:11 UTC 2017 : Successfully completed execution
Sun Feb 19 15:00:11 UTC 2017 : Method completed with status: 404
Logs from Test Request via API Gateway second Invocation
Response Body
"Hello, stranger!"
Response Headers
{
"x-powered-by": "Express",
"access-control-allow-origin": "*",
"content-type": "application/json; charset=utf-8",
"content-length": "18",
"etag": "W/\"12-E1p7iNXxJ4trMdmFBhlU9Q\"",
"date": "Mon, 13 Feb 2017 20:12:36 GMT",
"connection": "close",
"X-Amzn-Trace-Id": "<Trace-ID>"
}
Logs
Execution log for request test-request
Mon Feb 13 20:12:36 UTC 2017 : Starting execution for request: test-invoke-request
Mon Feb 13 20:12:36 UTC 2017 : HTTP Method: GET, Resource Path: /hello
Mon Feb 13 20:12:36 UTC 2017 : Method request path: {}
Mon Feb 13 20:12:36 UTC 2017 : Method request query string: {}
Mon Feb 13 20:12:36 UTC 2017 : Method request headers: {}
Mon Feb 13 20:12:36 UTC 2017 : Method request body before transformations:
Mon Feb 13 20:12:36 UTC 2017 : Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:<LAMBDA-FUNCTION-ID>:function:api/invocations
Mon Feb 13 20:12:36 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=*******************************************************************************************************************************************************************************************************************************************************************************************************************************************3e1b18, X-Amz-Date=20170213T201236Z, x-amzn-apigateway-api-id=965h04axki, X-Amz-Source-Arn=arn:aws:execute-api:eu-central-1:<ACCOUNT-ID>:965h04axki/null/GET/hello, Accept=application/json, User-Agent=AmazonAPIGateway_965h04axki, X-Amz-Security-Token=<TOKEN>
Mon Feb 13 20:12:36 UTC 2017 : Endpoint request body after transformations: {"resource":"/hello","path":"/hello","httpMethod":"GET","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"<ACCOUNT-ID>","resourceId":"ll6gw8","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"<ACCOUNT-ID>","cognitoIdentityId":null,"caller":"427402682812","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"<ACCESS-KEY>","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::<ACCOUNT-ID>:root","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_102)","user":"<ACCOUNT-ID>"},"resourcePath":"/hello","httpMethod":"GET","apiId":"965h04axki"},"body":null,"isBase64Encoded":false}
Mon Feb 13 20:12:36 UTC 2017 : Endpoint response body before transformations: {"statusCode":200,"body":"\"Hello, stranger!\"","headers":{"x-powered-by":"Express","access-control-allow-origin":"*","content-type":"application/json; charset=utf-8","content-length":"18","etag":"W/\"12-E1p7iNXxJ4trMdmFBhlU9Q\"","date":"Mon, 13 Feb 2017 20:12:36 GMT","connection":"close"},"isBase64Encoded":false}
Mon Feb 13 20:12:36 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=c3354327-f228-11e6-8c1d-ed11cc413770, Connection=keep-alive, Content-Length=315, Date=Mon, 13 Feb 2017 20:12:36 GMT, Content-Type=application/json}
Mon Feb 13 20:12:36 UTC 2017 : Method response body after transformations: "Hello, stranger!"
Mon Feb 13 20:12:36 UTC 2017 : Method response headers: {x-powered-by=Express, access-control-allow-origin=*, content-type=application/json; charset=utf-8, content-length=18, etag=W/"12-E1p7iNXxJ4trMdmFBhlU9Q", date=Mon, 13 Feb 2017 20:12:36 GMT, connection=close, X-Amzn-Trace-Id=Root=1-58a21334-8ea6c4b5944eebb873bc7d2e}
Mon Feb 13 20:12:36 UTC 2017 : Successfully completed execution
Mon Feb 13 20:12:36 UTC 2017 : Method completed with status: 200
I think the response "Cannot GET /" is coming from your Lambda function itself. Can you check API Gateway CW logs (or Test Invoke feature in console) to see what's different in the integration request and response in the first call?
I didn't see any real documentation about it (just this Medium post) but I also experienced the fact that a Lambda can be frozen until the first invocation, or in the case it's not called for a long time.
A solution is to schedule a regular invocation to wake up your lambda, with Amazon CloudWatch Events
I know that is an old question, but if you use TypeORM (or more in general, if you wrap all your Express middlewares within a .then() callback of a Promise), and you use context.callbackWaitsForEmptyEventLoop = false in your lambda handler, maybe this could help you: https://github.com/typeorm/typeorm/issues/5894
Long story short: avoid to set that flag to false, if possible, otherwise avoid to wrap the Express middlewares within the .then() callback and, for instance, initialize your db connection in the first Express middleware.

Rails: Timezone difference on local and production

I have a Sidekiq worker, fetching records from a remote Oracle database and saving it in a postgres database. Most of the data consists of date and time fields. The issue I'm getting on production is that it saves the data time in different timezone with 5 hours difference. Although it works fine on local. Here is an example:
From Oracle DB => 2016-01-27 07:59:29 +0500
Saved on local => 2016-01-27 07:59:29 -0500
On Production => 2016-01-27 02:59:29 -0500
In config/application.rb I have set:
config.time_zone = 'Eastern Time (US & Canada)'
What should I do to make it consistent on both local and production?
check this http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails, seems like your are doing some from the dont's section:
Time.now # Returns system time and ignores your configured time zone. (2015-08-27 14:09:36 +0200)
Time.parse("2015-08-27T12:09:36Z") # Will assume time string given is in the system's time zone. (2015-08-27 12:09:36 UTC)
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z") # Same problem as with Time.parse. (2015-08-27 12:09:36 UTC)
Date.today # This could be yesterday or tomorrow depending on the machine's time zone, see https://github.com/ramhoj/time-zone-article/issues/1 for more info. (Thu, 27 Aug 2015)
to aviod problem with TimeZone, just use:
Date.current # => Mon, 01 Feb 2016
DateTime.current # => Mon, 01 Feb 2016 17:32:18 +0000
Time.current # => Mon, 01 Feb 2016 17:33:17 UTC +00:00