@@ -98,17 +98,17 @@ func (s *AwsLambdaInvokeCmd) Run() error {
9898type AwsCloudfrontUpdateCmd struct {
9999 Region string `kong:"name='region',env='AWS_REGION'"`
100100 Function string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
101- FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE',type=filecontent "`
101+ FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE'"`
102102 CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
103- RedirectsFile string `kong:"name='redirects-file ',env='REDIRECTS_FILE',type=filecontent "`
104- RedirectsPrefixesFile string `kong:"name='redirects-prefixes-file ',env='REDIRECTS_PREFIXES_FILE',type=filecontent "`
103+ RedirectsJSON string `kong:"name='redirects-json ',env='REDIRECTS_JSON' "`
104+ RedirectsPrefixesJSON string `kong:"name='redirects-prefixes-json ',env='REDIRECTS_PREFIXES_JSON' "`
105105}
106106
107107func (s * AwsCloudfrontUpdateCmd ) Run () error {
108108 var err error
109109 ver := time .Now ().UTC ().Format (time .RFC3339 )
110110
111- zipdt , err := getLambdaFunctionZip (s .FunctionFile , s .RedirectsFile , s .RedirectsPrefixesFile )
111+ zipdt , err := getLambdaFunctionZip (s .FunctionFile , s .RedirectsJSON , s .RedirectsPrefixesJSON )
112112 if err != nil {
113113 return fmt .Errorf ("cannot create lambda function zip: %w" , err )
114114 }
@@ -228,15 +228,20 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
228228 return nil
229229}
230230
231- func getLambdaFunctionZip (funcdt , redirects , redirectsPrefixes string ) ([]byte , error ) {
231+ func getLambdaFunctionZip (funcFilename string , redirectsJSON string , redirectsPrefixesJSON string ) ([]byte , error ) {
232+ funcdt , err := os .ReadFile (funcFilename )
233+ if err != nil {
234+ return nil , fmt .Errorf ("failed to read lambda function file %q: %w" , funcFilename , err )
235+ }
236+
232237 var funcbuf bytes.Buffer
233- functpl := template .Must (template .New ("" ).Parse (funcdt ))
234- if err : = functpl .Execute (& funcbuf , struct {
238+ functpl := template .Must (template .New ("" ).Parse (string ( funcdt ) ))
239+ if err = functpl .Execute (& funcbuf , struct {
235240 RedirectsJSON string
236241 RedirectsPrefixesJSON string
237242 }{
238- redirects ,
239- redirectsPrefixes ,
243+ redirectsJSON ,
244+ redirectsPrefixesJSON ,
240245 }); err != nil {
241246 return nil , err
242247 }
0 commit comments