@@ -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'"`
101+ FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE',type=filecontent "`
102102 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' "`
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 "`
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 .RedirectsJSON , s .RedirectsPrefixesJSON )
111+ zipdt , err := getLambdaFunctionZip (s .FunctionFile , s .RedirectsFile , s .RedirectsPrefixesFile )
112112 if err != nil {
113113 return fmt .Errorf ("cannot create lambda function zip: %w" , err )
114114 }
@@ -228,20 +228,15 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
228228 return nil
229229}
230230
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-
231+ func getLambdaFunctionZip (funcdt , redirects , redirectsPrefixes string ) ([]byte , error ) {
237232 var funcbuf bytes.Buffer
238- functpl := template .Must (template .New ("" ).Parse (string ( funcdt ) ))
239- if err = functpl .Execute (& funcbuf , struct {
233+ functpl := template .Must (template .New ("" ).Parse (funcdt ))
234+ if err : = functpl .Execute (& funcbuf , struct {
240235 RedirectsJSON string
241236 RedirectsPrefixesJSON string
242237 }{
243- redirectsJSON ,
244- redirectsPrefixesJSON ,
238+ redirects ,
239+ redirectsPrefixes ,
245240 }); err != nil {
246241 return nil , err
247242 }
0 commit comments