This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | |
| // SPDX-License-Identifier: Apache-2.0 | |
| const { | |
| RawRsaKeyringNode, | |
| buildClient, | |
| CommitmentPolicy, | |
| } = require ('@aws-crypto/client-node') | |
| const { generateKeyPair } = require ('crypto') | |
| const { promisify } = require ('util') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const csvFilePath = './resources/field_enum.csv'; | |
| const csv = require('csvtojson'); | |
| const fs = require('fs'); | |
| csv() | |
| .fromFile(csvFilePath) | |
| .then((jsonObj) => { | |
| writeFileToDisk(jsonObj); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const zlib = require('zlib'); //inbuilt in NodeJs | |
| const sizeof = require('object-sizeof'); //npm | |
| const input = "Compressing messages and decompressing messages"; | |
| (async function () { | |
| // compress | |
| console.info(`String size: ${sizeof(input)}`); | |
| let buffer = await zlib.deflateSync(input); | |
| const compressedString = buffer.toString('base64'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.BufferedReader; | |
| import java.io.ByteArrayInputStream; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.InputStreamReader; | |
| import java.util.Base64; | |
| import java.util.zip.GZIPInputStream; | |
| import java.util.zip.GZIPOutputStream; | |
| public class GzipUtil { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseDotNotation(str, obj, result) { | |
| const keys = str.split("."); | |
| const l = Math.max(1, keys.length - 1); | |
| let key, i; | |
| for (i = 0; i < l; ++i) { | |
| key = keys[i]; | |
| result[key] = result[key] || {}; | |
| result = result[key]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function execute() { | |
| const startTime = new Date(); | |
| const promises = []; | |
| for (let i = 1; i < 11; i++) { | |
| promises.push(someTimeConsumingFunction(i)); | |
| } | |
| await Promise.all(promises); | |
| console.log(`Total time taken: ${(new Date() - startTime)} millis`); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const result = describedby.map(value => { | |
| const simplifiedObj = {}; | |
| simplifiedObj[value.key] = value.value; | |
| return simplifiedObj; | |
| }).reduce(ArrayToObjectReducer); | |
| const ArrayToObjectReducer = (accumulator, currentValue) => { | |
| for (const key in currentValue) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function flattenObject(prefix, inData) { | |
| let result = {}; | |
| for (const key in inData) { | |
| if (key == 'DescribedBy') { | |
| result = Object.assign({}, result, parseDescribedBy(prefix, inData[key])); | |
| } else if (typeof inData[key] === 'object' && inData[key] !== null) { | |
| if ('ItemInvolvesNetworkTrail' != key){ | |
| result = Object.assign({}, result, flattenObject(formatKey(prefix, key), inData[key])); | |
| } | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let newString = ''; | |
| for (let i = 0; i < formattedKey.length; i++) { | |
| if (i != 0 && formattedKey[i].match(/[A-Z]/) != null) { | |
| if (formattedKey[i + 1] && !(formattedKey[i + 1].match(/[A-Z]/) != null)) { | |
| newString = `${newString}_${formattedKey[i]}`; | |
| } else { | |
| newString = `${newString}${formattedKey[i]}`; | |
| } | |
| } else { | |
| newString = `${newString}${formattedKey[i]}`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jest.mock('./eventProcessor'); | |
| const lambdaTester = require('lambda-tester').noVersionCheck(); | |
| const handler = require('./index').handler; | |
| const testEvent = require('./resources/s3_event_fls_1'); | |
| const processor = require('./eventProcessor'); | |
| describe('handler', function () { | |
| beforeAll(() => { |
NewerOlder