@@ -34,6 +34,8 @@ const prices = require('./prices');
34
34
const { STATES } = require ( '../local/artillery-worker-local' ) ;
35
35
36
36
const { SQS_QUEUES_NAME_PREFIX } = require ( '../aws/constants' ) ;
37
+ const ensureS3BucketExists = require ( '../aws/aws-ensure-s3-bucket-exists' ) ;
38
+ const getAccountId = require ( '../aws/aws-get-account-id' ) ;
37
39
38
40
const createSQSQueue = require ( '../aws/aws-create-sqs-queue' ) ;
39
41
@@ -91,6 +93,20 @@ class PlatformLambda {
91
93
platformConfig [ 'lambda-role-arn' ] || platformConfig [ 'lambdaRoleArn' ] ;
92
94
93
95
this . platformOpts = platformOpts ;
96
+ this . s3LifecycleConfigurationRules = [
97
+ {
98
+ Expiration : { Days : 2 } ,
99
+ Filter : { Prefix : '/lambda' } ,
100
+ ID : 'RemoveAdHocTestData' ,
101
+ Status : 'Enabled'
102
+ } ,
103
+ {
104
+ Expiration : { Days : 7 } ,
105
+ Filter : { Prefix : '/' } ,
106
+ ID : 'RemoveTestRunMetadata' ,
107
+ Status : 'Enabled'
108
+ }
109
+ ] ;
94
110
95
111
this . artilleryArgs = [ ] ;
96
112
}
@@ -103,7 +119,7 @@ class PlatformLambda {
103
119
artillery . log ( 'λ Creating AWS Lambda function...' ) ;
104
120
105
121
await setDefaultAWSCredentials ( AWS ) ;
106
- this . accountId = await this . getAccountId ( ) ;
122
+ this . accountId = await getAccountId ( ) ;
107
123
108
124
const dirname = temp . mkdirSync ( ) ; // TODO: May want a way to override this by the user
109
125
const zipfile = temp . path ( { suffix : '.zip' } ) ;
@@ -313,7 +329,10 @@ class PlatformLambda {
313
329
await this . createZip ( dirname , zipfile ) ;
314
330
315
331
artillery . log ( 'Preparing AWS environment...' ) ;
316
- const bucketName = await this . ensureS3BucketExists ( ) ;
332
+ const bucketName = await ensureS3BucketExists (
333
+ this . region ,
334
+ this . s3LifecycleConfigurationRules
335
+ ) ;
317
336
this . bucketName = bucketName ;
318
337
319
338
const s3path = await this . uploadLambdaZip ( bucketName , zipfile ) ;
@@ -639,42 +658,6 @@ class PlatformLambda {
639
658
} ) ;
640
659
}
641
660
642
- // TODO: Move into reusable platform util
643
- async ensureS3BucketExists ( ) {
644
- const accountId = await this . getAccountId ( ) ;
645
- // S3 and Lambda have to be in the same region, which means we can't reuse
646
- // the bucket created by Pro to store Lambda deployment zips
647
- const bucketName = `artilleryio-test-data-${ this . region } -${ accountId } ` ;
648
- const s3 = new AWS . S3 ( { region : this . region } ) ;
649
-
650
- try {
651
- await s3 . listObjectsV2 ( { Bucket : bucketName , MaxKeys : 1 } ) . promise ( ) ;
652
- } catch ( s3Err ) {
653
- if ( s3Err . code === 'NoSuchBucket' ) {
654
- const res = await s3 . createBucket ( { Bucket : bucketName } ) . promise ( ) ;
655
- } else {
656
- throw s3Err ;
657
- }
658
- }
659
-
660
- return bucketName ;
661
- }
662
-
663
- // TODO: Move into reusable platform util
664
- async getAccountId ( ) {
665
- let stsOpts = { } ;
666
- if ( process . env . ARTILLERY_STS_OPTS ) {
667
- stsOpts = Object . assign (
668
- stsOpts ,
669
- JSON . parse ( process . env . ARTILLERY_STS_OPTS )
670
- ) ;
671
- }
672
-
673
- const sts = new AWS . STS ( stsOpts ) ;
674
- const awsAccountId = ( await sts . getCallerIdentity ( { } ) . promise ( ) ) . Account ;
675
- return awsAccountId ;
676
- }
677
-
678
661
async createLambdaRole ( ) {
679
662
const ROLE_NAME = 'artilleryio-default-lambda-role-20230116' ;
680
663
const POLICY_NAME = 'artilleryio-lambda-policy-20230116' ;
0 commit comments