@@ -30,9 +30,15 @@ type AwsS3UpdateConfigCmd struct {
3030 Region string `kong:"name='region',env='AWS_REGION'"`
3131 S3Bucket string `kong:"name='s3-bucket',env='AWS_S3_BUCKET'"`
3232 S3Config string `kong:"name='s3-website-config',env='AWS_S3_CONFIG'"`
33+ DryRun bool `kong:"name='dry-run',env='DRY_RUN'"`
3334}
3435
3536func (s * AwsS3UpdateConfigCmd ) Run () error {
37+ if s .DryRun {
38+ log .Printf ("INFO: Dry run mode enabled. Configuration:\n Region: %s\n S3Bucket: %s\n S3Config: %s\n " , s .Region , s .S3Bucket , s .S3Config )
39+ return nil
40+ }
41+
3642 file , err := os .ReadFile (s .S3Config )
3743 if err != nil {
3844 return fmt .Errorf ("failed to read s3 config file %s: %w" , s .S3Config , err )
@@ -74,9 +80,15 @@ func (s *AwsS3UpdateConfigCmd) Run() error {
7480type AwsLambdaInvokeCmd struct {
7581 Region string `kong:"name='region',env='AWS_REGION'"`
7682 LambdaFunction string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
83+ DryRun bool `kong:"name='dry-run',env='DRY_RUN'"`
7784}
7885
7986func (s * AwsLambdaInvokeCmd ) Run () error {
87+ if s .DryRun {
88+ log .Printf ("INFO: Dry run mode enabled. Configuration:\n Region: %s\n LambdaFunction: %s\n " , s .Region , s .LambdaFunction )
89+ return nil
90+ }
91+
8092 svc := lambda .New (session .Must (session .NewSessionWithOptions (session.Options {
8193 SharedConfigState : session .SharedConfigEnable ,
8294 })), & aws.Config {
@@ -100,19 +112,26 @@ type AwsCloudfrontUpdateCmd struct {
100112 Function string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
101113 FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE'"`
102114 CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
103- RedirectsJSON string `kong:"name='redirects-json',env='REDIRECTS_JSON'"`
104- RedirectsPrefixesJSON string `kong:"name='redirects-prefixes-json',env='REDIRECTS_PREFIXES_JSON'"`
115+ RedirectsFile string `kong:"name='redirects-file',env='REDIRECTS_FILE'"`
116+ RedirectsPrefixesFile string `kong:"name='redirects-prefixes-file',env='REDIRECTS_PREFIXES_FILE'"`
117+ DryRun bool `kong:"name='dry-run',env='DRY_RUN'"`
105118}
106119
107120func (s * AwsCloudfrontUpdateCmd ) Run () error {
108121 var err error
109122 ver := time .Now ().UTC ().Format (time .RFC3339 )
110123
111- zipdt , err := getLambdaFunctionZip (s .FunctionFile , s .RedirectsJSON , s .RedirectsPrefixesJSON )
124+ zipdt , err := getLambdaFunctionZip (s .FunctionFile , s .RedirectsFile , s .RedirectsPrefixesFile , s . DryRun )
112125 if err != nil {
113126 return fmt .Errorf ("cannot create lambda function zip: %w" , err )
114127 }
115128
129+ if s .DryRun {
130+ log .Printf ("INFO: Dry run mode enabled. Configuration:\n Region: %s\n Function: %s\n FunctionFile: %s\n CloudfrontID: %s\n RedirectsFile: %s\n RedirectsPrefixesFile: %s\n " ,
131+ s .Region , s .Function , s .FunctionFile , s .CloudfrontID , s .RedirectsFile , s .RedirectsPrefixesFile )
132+ return nil
133+ }
134+
116135 svc := lambda .New (session .Must (session .NewSessionWithOptions (session.Options {
117136 SharedConfigState : session .SharedConfigEnable ,
118137 })), & aws.Config {
@@ -228,24 +247,39 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
228247 return nil
229248}
230249
231- func getLambdaFunctionZip (funcFilename string , redirectsJSON string , redirectsPrefixesJSON string ) ([]byte , error ) {
250+ func getLambdaFunctionZip (funcFilename , redirectsFile , redirectsPrefixesFile string , dryrun bool ) ([]byte , error ) {
232251 funcdt , err := os .ReadFile (funcFilename )
233252 if err != nil {
234253 return nil , fmt .Errorf ("failed to read lambda function file %q: %w" , funcFilename , err )
235254 }
236255
256+ redirects , err := os .ReadFile (redirectsFile )
257+ if err != nil {
258+ return nil , fmt .Errorf ("failed to read redirects file %q: %w" , redirectsFile , err )
259+ }
260+
261+ redirectsPrefixes , err := os .ReadFile (redirectsPrefixesFile )
262+ if err != nil {
263+ return nil , fmt .Errorf ("failed to read redirects prefixes file %q: %w" , redirectsPrefixesFile , err )
264+ }
265+
237266 var funcbuf bytes.Buffer
238267 functpl := template .Must (template .New ("" ).Parse (string (funcdt )))
239268 if err = functpl .Execute (& funcbuf , struct {
240269 RedirectsJSON string
241270 RedirectsPrefixesJSON string
242271 }{
243- redirectsJSON ,
244- redirectsPrefixesJSON ,
272+ string ( redirects ) ,
273+ string ( redirectsPrefixes ) ,
245274 }); err != nil {
246275 return nil , err
247276 }
248277
278+ if dryrun {
279+ log .Printf ("INFO: Dry run mode enabled. Lambda Function Definition:\n \n %s\n " , funcbuf .String ())
280+ return nil , nil
281+ }
282+
249283 tmpdir , err := os .MkdirTemp ("" , "lambda-zip" )
250284 if err != nil {
251285 return nil , err
0 commit comments