Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.handler = async (event,context,callback) => {
- // console.log('Received event:', JSON.stringify(event, null, 2));
- var key=event.queryStringParameters.ref;
- // console.log('index.handler started with key : '+key);
- var RemoteServer='aaa.bbb.ccc.ddd';
- var net = require('net');
- var responce={
- "statusCode": 200,
- "headers": {
- "Content-Type": "*/*"
- }
- };
- var socket = new net.Socket();
- socket.setEncoding('utf8');
- socket.on('close', () => {
- console.log('Close.');
- console.log(JSON.stringify(responce));
- callback(null, JSON.stringify(responce));
- });
- socket.on('connect', () => {
- // console.log('Connect');
- var senddata='1,'+key;
- // console.log(('About to write :'+senddata));
- socket.write(senddata);
- console.log(('Wrote :'+senddata));
- });
- socket.on('data', (data) => {
- console.log('Data.');
- responce.body = data;
- console.log(JSON.stringify(responce));
- socket.end();
- });
- socket.on('end', () => {
- console.log('End.');
- console.log(JSON.stringify(responce));
- });
- socket.on('error', (error) => {
- console.log('Error' + error);
- socket.destroy;
- callback(error);
- });
- socket.on('timeout', () => {
- console.log('Timeout');
- socket.close;
- callback('Timeout');
- });
- socket.connect(11010, RemoteServer, () => {
- // console.log('socket connect');
- });
- callback(null,responce); // This is here to get this to do anything.
- };
- START RequestId: 7e1876fe-4255-12de-56d6-c187bcfff9ee Version: $LATEST
- Wrote :1,R9H39X
- Data.
- {"statusCode":200,"headers":{"Content-Type":"*/*"},"body":"<?xml version="1.0" encoding="utf-8"?>rn<group>rn <data>rn <name>COLIN MANNING</name>rn <from>26/03/2018</from>rn <to>31/05/2018</to>rn <room>A31</room>rn <location>X,Y</location>rn </data>rn</group>rn"}
- End.
- {"statusCode":200,"headers":{"Content-Type":"*/*"},"body":"<?xml version="1.0" encoding="utf-8"?>rn<group>rn <data>rn <name>COLIN MANNING</name>rn <from>26/03/2018</from>rn <to>31/05/2018</to>rn <room>A31</room>rn <location>X,Y</location>rn </data>rn</group>rn"}
- Close.
- {"statusCode":200,"headers":{"Content-Type":"*/*"},"body":"<?xml version="1.0" encoding="utf-8"?>rn<group>rn <data>rn <name>COLIN MANNING</name>rn <from>26/03/2018</from>rn <to>31/05/2018</to>rn <room>A31</room>rn <location>X,Y</location>rn </data>rn</group>rn"}
- END RequestId: 7e1876fe-4255-12de-56d6-c187bcfff9ee
- REPORT RequestId: 7e1876fe-4255-12de-56d6-c187bcfff9ee Duration: 178.76 ms Billed Duration: 200 ms Memory Size: 1536 MB Max Memory Used: 33 MB
- {"statusCode":200,"headers":{"Content-Type":"*/*"}}
- START RequestId: c3dc7e69-87aa-1608-76d4-093a0e28711b Version: $LATEST
- END RequestId: c3dc7e69-87aa-1608-76d4-093a0e28711b
- REPORT RequestId: c3dc7e69-87aa-1608-76d4-093a0e28711b Duration: 3.43 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 33 MB
- null
Add Comment
Please, Sign In to add comment