Skip to content

Commit

Permalink
Create AWS SDK s3 client on demand when needed to sort out S3 client …
Browse files Browse the repository at this point in the history
…require and creation overhead from function coldstart overhead while profiling
  • Loading branch information
Serkan ÖZAL committed May 2, 2022
1 parent c4a64de commit 066a6a7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const inspector = require('inspector')
const session = new inspector.Session()
const S3 = require('aws-sdk/clients/s3')
const s3Client = new S3()

let s3Client

async function _sessionPost(key, obj = {}) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -36,6 +36,10 @@ async function _putProfilingDataToS3(
functionName,
awsRequestId
) {
if (!s3Client) {
const S3 = require('aws-sdk/clients/s3')
s3Client = new S3()
}
const params = {
Body: JSON.stringify(profilingData),
Bucket: bucketName,
Expand Down

0 comments on commit 066a6a7

Please sign in to comment.