Skip to content

Commit

Permalink
Merge pull request #453 from wellcomecollection/update-deploy-script-…
Browse files Browse the repository at this point in the history
…for-sdk-v3

deploy script uses sdk v3
  • Loading branch information
agnesgaroux authored Dec 2, 2024
2 parents 12d9b18 + 6aa3fee commit be78781
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 15 deletions.
30 changes: 17 additions & 13 deletions cloudfront/invalidation/lambda/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@ const s3Bucket = 'wellcomecollection-platform-infra'
const s3Key = 'lambdas/cloudfront_invalidation/sns_handler.zip'
const roleArn = 'arn:aws:iam::760097843905:role/platform-ci'

const AWS = require('aws-sdk');
const fs = require('fs');
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3")
const { fromTemporaryCredentials } = require("@aws-sdk/credential-providers")
const fs = require("fs")

const roleCredentials = new AWS.ChainableTemporaryCredentials({params: {RoleArn: roleArn}});
const s3 = new AWS.S3({ apiVersion: '2006-03-01' , credentials: roleCredentials});
const s3Client = new S3Client({
credentials: fromTemporaryCredentials({
params: { RoleArn: roleArn }
})
});

try {
const data = fs.readFileSync(zipLocation);
const data = fs.readFileSync(zipLocation)

const params = {
Body: data,
const command = new PutObjectCommand({
Bucket: s3Bucket,
Key: s3Key,
Body: data,
ACL: 'private',
ContentType: 'application/zip',
};
ContentType: 'application/zip'
})

s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log('Finished uploading ' + zipLocation + ' to s3://' + s3Bucket + '/' + s3Key);
});
s3Client.send(command, function(err, data) {
if (err) console.log(err, err.stack)
else console.log(`Finished uploading ${zipLocation} to s3://${s3Bucket}/${s3Key}`)
})

} catch (e) {
console.log('Error:', e.stack);
Expand Down
4 changes: 3 additions & 1 deletion cloudfront/invalidation/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"dockerDeployLocal": "yarn dockerBuildLocal && docker run weco_invalidation_lambda -v ~/.aws:/root/.aws yarn deploy"
},
"dependencies": {
"@aws-sdk/client-cloudfront": "^3.699.0"
"@aws-sdk/client-cloudfront": "^3.699.0",
"@aws-sdk/client-s3": "3.703.0",
"@aws-sdk/credential-providers": "^3.699.0"
}
}
Loading

0 comments on commit be78781

Please sign in to comment.