Getting NO_STATUS_CODE_FROM_LAMBDA error when making ssr get calls on now - vue.js

I'm running a nuxt universal app on now.sh which makes an ssr get call to a https://getcockpit.com/ server somewhere else. When I open the app I get a 502 error with code "NO_STATUS_CODE_FROM_LAMBDA".
Running it locally or deploying it as a spa instead of universal app works just fine because then the calls aren't made from lambda but from my machine I guess. My webserver running the getcockpit-cms does not receive any call from now according to it's logs so the problem doesn't seem to be on that side.
The now.sh logs really don't say much to me. The only thing I found is "Process excited before completing request" but that doesn't help me either.
'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
data: undefined },
request:
Writable {
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
domain: null,
_events: { response: [Function], error: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
_options:
{ protocol: 'http:',
maxRedirects: 21,
maxBodyLength: 10485760,
path: '/api/singletons/get/intro',
method: 'GET',
headers: [Object],
agent: undefined,
auth: undefined,
hostname: 'localhost',
port: '3000',
nativeProtocols: [Object],
pathname: '/api/singletons/get/intro' },
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function],
_currentRequest:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 6,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'GET /api/singletons/get/intro HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nx-real-ip: 5.149.20.127\r\nsec-fetch-user: ?1\r\nsec-fetch-site: none\r\nupgrade-insecure-requests: 1\r\ncache-control: no-cache\r\nx-now-trace: zrh1\r\nx-now-deployment-url: BLURRED-NOW-DEPLOYMENT-URL\r\nx-zeit-co-forwarded-for: 5.149.20.127\r\naccept-language: en-GB,en-US;q=0.9,en;q=0.8,de;q=0.7\r\nx-forwarded-proto: https\r\nsec-fetch-mode: navigate\r\nx-forwarded-for: 5.149.20.127\r\nuser-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36\r\naccept-encoding: gzip, deflate\r\nx-now-id: clckl-1566116017296-db7c5240b52c\r\npragma: no-cache\r\nx-forwarded-host: BLURRED-NOW-DEPLOYMENT-URL\r\nconnection: close\r\nAuthorization: Bearer BLURRED-API-KEY\r\nHost: localhost:3000\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'GET',
path: '/api/singletons/get/intro',
_ended: false,
res: null,
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
_redirectable: [Circular],
[Symbol(outHeadersKey)]: [Object] },
_currentUrl: 'http://localhost:3000/api/singletons/get/intro' },
response: undefined,
isAxiosError: true,
toJSON: [Function] }
END RequestId: 5153a263-0ac9-4bf5-9c7d-4422783386ba
REPORT RequestId: 5153a263-0ac9-4bf5-9c7d-4422783386ba Duration: 234.13 ms Billed Duration: 300 ms Memory Size: 3008 MB Max Memory Used: 97 MB
RequestId: 5153a263-0ac9-4bf5-9c7d-4422783386ba Process exited before completing request
START RequestId: f32bcba9-aea6-46d0-9269-c0544a211fff Version: $LATEST
2019-08-18T08:13:39.117Z f32bcba9-aea6-46d0-9269-c0544a211fff λ Cold start took: 339.379719ms
END RequestId: f32bcba9-aea6-46d0-9269-c0544a211fff
REPORT RequestId: f32bcba9-aea6-46d0-9269-c0544a211fff Duration: 115.83 ms Billed Duration: 200 ms Memory Size: 3008 MB Max Memory Used: 53 MB
I would expect now.sh or rather lambda to make the call and ssr my app.

Related

Shopify Admin API create customer has odd response

I'm able to successfully pull orders via the Admin API. I now am creating a custom create account widget and am using the same fetch methodology I used for getting the orders but posting to create the customer. Here is the fetch call:
const shopifyUserQuery = `
query {
customer {
first_name: ${values.firstName},
last_name: ${values.lastName},
email: ${values.email},
verified_email: true,
password: ${values.password}
password_confirmation: ${values.password},
send_email_welcome = false;
}
}
`
const shopifyUser = await fetch(process.env.SHOPIFY_ADMIN_API_URL, {
'body': shopifyUserQuery,
'method': 'post',
'headers': {
'X-Shopify-Access-Token': shopifyAdminAccessToken,
'Content-Type': 'application/graphql',
},
}).then((res) => console.log(res))
Now, the response is really odd - no errors, nothing just an odd blend of content in a zipped file:
<ref *1> Gunzip {
_writeState: Uint32Array(2) [ 0, 0 ],
_readableState: ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: [],
flowing: null,
ended: false,
endEmitted: false,
reading: false,
constructed: true,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
destroyed: false,
errored: null,
closed: false,
closeEmitted: false,
defaultEncoding: 'utf8',
awaitDrainWriters: null,
multiAwaitDrain: false,
readingMore: false,
dataEmitted: false,
decoder: null,
encoding: null,
[Symbol(kPaused)]: null
},
_events: [Object: null prototype] {
prefinish: [Function: prefinish],
unpipe: [Function: onunpipe],
error: [ [Function: onerror], [Function (anonymous)] ],
close: [Function: bound onceWrapper] { listener: [Function: onclose] },
finish: [Function: bound onceWrapper] { listener: [Function: onfinish] }
},
_eventsCount: 5,
_maxListeners: undefined,
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 109,
writing: true,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: [Function: nop],
writelen: 109,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 1,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
allowHalfOpen: true,
bytesWritten: 0,
_handle: Zlib {
onerror: [Function: zlibOnError],
buffer: <Buffer 1f 8b 08 00 00 00 00 00 04 03 25 8c 31 0a 80 30 10 04 bf 72 6c a5 10 6c 42 52 e4 15 f6 9a e2 90 20 42 bc 83 44 ab e0 df 0d ca 56 c3 30 db 90 4a d1 52 ... 59 more bytes>,
cb: [Function (anonymous)],
availOutBefore: 16384,
availInBefore: 109,
inOff: 0,
flushFlag: 2,
[Symbol(owner_symbol)]: [Circular *1]
},
_outBuffer: <Buffer 7b 22 65 72 72 6f 72 73 22 3a 5b 7b 22 6d 65 73 73 61 67 65 22 3a 22 50 61 72 73 65 20 65 72 72 6f 72 20 6f 6e 20 5c 22 2e 5c 22 20 28 65 72 72 6f 72 ... 16334 more bytes>,
_outOffset: 0,
_chunkSize: 16384,
_defaultFlushFlag: 2,
_finishFlushFlag: 2,
_defaultFullFlushFlag: 3,
_info: undefined,
_maxOutputLength: 4294967296,
_level: -1,
_strategy: 0,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: null,
[Symbol(kError)]: null
}
Again, this admin token key does work but even if there were scope or perm issues (I did double check that my app has customer read and write scope) I'd expect a better error. Any help is appreciated.
Query Operation in Shopify GraphQL are type of get request where you can only get the demanded query list.
To edit or update anything on store you need to use Mutation operations
(admin api required)
mutation test {
customerCreate(input: {firstName: "", lastName: "", phone: "", email: ""})
}
for more clarity please visit - Shopify GraphQL
In the image you can see how to add a mutation operation.

Wait for file over ssh

I would like to do something like:
- name: Wait until the file is touched
ansible.builtin.wait_for:
path: 192.168.1.1:/home/test.txt
timeout: 300
where 192.168.1.1 is some remote host I am connected to. Is this possible?
I don't believe it's possible with wait_for module.
My workaround is to use until:
- name: Wait until file exists on remote.
shell: ssh $USER#192.168.1.1 ls /home/test.txt
register: filecheck
until: filecheck.stdout == "/home/test.txt"
retries: 10
delay: 1
I copied the file to the host while the playbook was running through the 9th attempt:
changed: [localhost] => {
"attempts": 9,
"changed": true,
"cmd": "ssh root#192.168.1.1 ls /home/test.txt",
"delta": "0:00:01.548091",
"end": "2022-08-11 15:31:05.276277",
"invocation": {
"module_args": {
"_raw_params": "ssh root#192.168.1.1 ls /home/test.txt",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": false
}
},
"msg": "",
"rc": 0,
"start": "2022-08-11 15:31:03.728186",
"stderr": "",
"stderr_lines": [],
"stdout": "/home/test.txt",
"stdout_lines": [
"/home/test.txt"
]

Ansible Register access invocation_module?

I have a playbook that downloads a list of files from S3, this list can be set dynamically by utilizing with_items and |default([]).
After pulling this I need to get a list of destinations of the stored files and perform other actions. I registered the var output and see that invocation module_args has the value "Dest" which is what i want to access.
I've tried things like:
debug: msg="{{ item }}"
with_items: "{{ output.results }}
Or even accessing output.invocation but get undefined variable
Task:
- name: "Download Apps from S3"
aws_s3:
bucket: "{{ resource_bucket_name }}"
object: "{{ s3_apps[item].src }}"
dest: "{{ s3_apps[item].dest }}"
mode: get
with_items: "{{ s3_apps_decl |default([]) }}"
register: output
My output variable with debug:
"msg": [
{
"ansible_loop_var": "item",
"changed": true,
"failed": false,
"invocation": {
"module_args": {
"aws_access_key": null,
"aws_secret_key": null,
"bucket": "bucket-resources",
"debug_botocore_endpoint_logs": false,
"dest": "/tmp/test_app.tgz",
"dualstack": false,
"ec2_url": null,
"encrypt": true,
"encryption_kms_key_id": null,
"encryption_mode": "AES256",
"expiry": 600,
"headers": null,
"ignore_nonexistent_bucket": false,
"marker": "",
"max_keys": 1000,
"metadata": null,
"mode": "get",
"object": "test_app.tgz",
"overwrite": "always",
"permission": [
"private"
],
"prefix": "",
"profile": null,
"region": null,
"retries": 0,
"rgw": false,
"s3_url": null,
"security_token": null,
"src": null,
"validate_certs": true,
"version": null
}
},
"item": "test_app",
"msg": "GET operation complete"
},
{
"ansible_loop_var": "item",
"changed": true,
"failed": false,
"invocation": {
"module_args": {
"aws_access_key": null,
"aws_secret_key": null,
"bucket": "bucket-resources",
"debug_botocore_endpoint_logs": false,
"dest": "/tmp/testanotherapp.spl",
"dualstack": false,
"ec2_url": null,
"encrypt": true,
"encryption_kms_key_id": null,
"encryption_mode": "AES256",
"expiry": 600,
"headers": null,
"ignore_nonexistent_bucket": false,
"marker": "",
"max_keys": 1000,
"metadata": null,
"mode": "get",
"object": "testanotherapp.spl",
"overwrite": "always",
"permission": [
"private"
],
"prefix": "",
"profile": null,
"region": null,
"retries": 0,
"rgw": false,
"s3_url": null,
"security_token": null,
"src": null,
"validate_certs": true,
"version": null
}
},
"item": "testanotherapp",
"msg": "GET operation complete"
}
]
}
My expected output would be to define a variable that outputs:
['/tmp/testanotherapp.spl'.'/tmp/test_app.tgz']
I've tried set_fact with the similar syntax as my task above however that only saves the last value...
What you should expect in output is exactly what you get since you are receiving the return values from an aws_s3 module call which you are registering in a loop.
Now, if you want to get a list of only paths of all dest you have saved on your target host, you have to extract the corresponding attribute from your data structure.
- name: Show a list of dest paths from previous run
debug:
msg: "{{ output.results | map(attribute='invocation.module_args.dest') | list }}"

ldapjs connecting to LDAP (ldap.forumsys.com) fails

Here is an online LDPA test server, http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
So I did some simple script to test it but I am always getting unwanted response.
Here is my code:
const ldap = require('ldapjs');
const assert = require('assert');
// LDAP Connection Settings
const server = "ldap.forumsys.com";
const uid = "tesla"
const password = "password"; // User password
// Create client and bind to AD
const client = ldap.createClient({
url: `ldap://${server}`
});
// Search AD for user
const searchOptions = {
filter: '(uid=${uid})'
};
// client.bind(`uid=tesla,dc=example,dc=com`,password,err => {
// assert.ifError(err);
// });
client.search(`cn=read-only-admin,dc=example,dc=com`,searchOptions,(err,res) => {
assert.ifError(err);
res.on('searchEntry', entry => {
console.log(entry.object.name);
});
res.on('searchReference', referral => {
console.log('referral: ' + referral.uris.join());
});
res.on('error', err => {
console.error('error: ' + err.message);
});
res.on('end', result => {
console.log(result);
});
});
// Wrap up
client.unbind( err => {
assert.ifError(err);
});
And I am getting this back by running the app.js
SearchResponse {
messageID: 1,
protocolOp: 101,
controls: [],
log:
Logger {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_isSimpleChild: true,
_level: 30,
streams: [ [Object] ],
serializers: { req: [Function], res: [Function], err: [Function] },
src: false,
fields:
{ name: 'ldapjs',
component: 'client',
hostname: 'will-ThinkPad-T440p',
pid: 17485,
clazz: 'Client' } },
status: 0,
matchedDN: '',
errorMessage: '',
referrals: [],
connection:
Socket {
connecting: false,
_hadError: false,
_handle:
TCP {
reading: true,
owner: [Circular],
onread: [Function: onread],
onconnection: null,
writeQueueSize: 0 },
_parent: null,
_host: 'ldap.forumsys.com',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: false,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
data: [Function: onData],
close: [Object],
end: [Function: onEnd],
error: [Function: onSocketError],
timeout: [Function: onTimeout] },
_eventsCount: 7,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_bytesDispatched: 79,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
[Symbol(asyncId)]: 8,
[Symbol(bytesRead)]: 0 },
attributes: [],
notAttributes: [],
sentEntries: 0 }
which does not contain any information around "Tesla"......
Could be that this section:
// Search AD for user
const searchOptions = {
filter: '(uid=${uid})'
};
Needs backticks like the url settings above? If this is a dynamic value, you should add those to transform it into a string literal, like:
// Search AD for user
const searchOptions = {
filter: `(uid=${uid})`
};
const searchOptions = {
filter: '(uid=${uid})'
};
The above section is incorrect.
Should be
const searchOptions = {
filter: `(uid=${uid})`
};
I see Gustav as already given the correct answer. But adding to that the reason is when using ' the variable replacement does not happen as you have expected. to build the string like this you need to use `
Anyway since you have written an LDAP test server, there are already written test servers to achieve that, for example, you can use
https://hub.docker.com/r/upekshejay/simple-ldap-test-server

How to get the name of a request via Nock object

At the point in my test code where I check assert that all nocks have been called, I have a semi-useful error message to dumps out if a nock wasn't called (since the default error message is useless):
try {
assertions(data, result);
if (assertNock !== null) {
// Expect that all mocked calls were made
if (nock.isDone() !== !!assertNock) {
console.error('One or more of your Nock matchers was never called.');
}
expect(nock.isDone()).toBe(!!assertNock);
}
done();
} catch (err) {
...
}
However, I'd like to be able to specify which call wasn't made. But, I can't seem to find a way to get that information from the nock object, which looks like:
{ [Function: startScope]
emitter:
EventEmitter {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined },
define: [Function: define],
loadDefs: [Function: loadDefs],
load: [Function: load],
enableNetConnect: [Function: enableNetConnect],
disableNetConnect: [Function: disableNetConnect],
removeInterceptor: [Function: removeInterceptor],
activeMocks: [Function: activeMocks],
pendingMocks: [Function: pendingMocks],
isDone: [Function: isDone],
isActive: [Function: isActive],
activate: [Function: activate],
cleanAll: [Function: cleanAll],
recorder:
{ rec: [Function: record],
clear: [Function: clear],
play: [Function] },
back: { [Function: Back] setMode: [Function], fixtures: null, currentMode: 'dryrun' },
restore: [Function: restore]
}
How can I get useful/identifying information about the request that was't made from the nock object?
As per the documentation, interceptors are removed once they have been called. With that knowledge, one can then use nock.activeMocks() which will return an array of items that are still active. If you have added .persist() to any of the nocks they will still be in the list. In that case you may want to use nock.pendingMocks() which will only return the nocks that haven't yet been called.
nock.activeMocks(); // [ 'GET https://www.example.com:443/fake/url', 'POST https://sts.amazonaws.com:443/' ]
nock.pendingMocks(); // [ 'GET https://www.example.com:443/fake/url' ]