namespace :lambdas do namespace :<%= @lambda.name %> do task test: "lambdas:test" desc "Update the <%= @lambda.name %> lambda code (creating & uploading the ZIP file)" task upload_zip: :create_zip do tck_lambda = Tck::Lambdas::AwsFunction.new(:<%= @lambda.name %>) params = "--function-name #{tck_lambda.function_name} " << "--zip-file fileb://#{tck_lambda.zip_file}" puts `aws lambda update-function-code #{params}` end desc "Generate lambda's ZIP file w/ source/* code" task :create_zip do tck_lambda = Tck::Lambdas::AwsFunction.new(:<%= @lambda.name %>) puts "Creating #{tck_lambda.zip_file}..." FileUtils.rm(tck_lambda.zip_file, force: true) cmd = "cd #{tck_lambda.dir}/source &&\\\n" << "mv #{tck_lambda.name}.js #{tck_lambda.function_name}.js &&\\\n" << "zip -r #{tck_lambda.zip_file} * &&\\\n" << "mv #{tck_lambda.function_name}.js #{tck_lambda.name}.js" puts cmd puts `#{cmd}` end desc "Create the <%= @lambda.name %> lambda function in AWS Lambda w/ .lambda.yml." task create_lambda: :create_zip do tck_lambda = Tck::Lambdas::AwsFunction.new(:<%= @lambda.name %>) puts "\n#{tck_lambda.function_name} & #{tck_lambda.test_function_name} lambdas will be created with:" puts "\n #{tck_lambda.zip_file}\n\n...using the following parameters read from current .lambdas.yml:" tck_lambda.conf.each do |prop, value| puts " - #{prop}: #{value}" end [] printf "\nContinue?? Press [Ctrl+C] to cancel." STDIN.gets [tck_lambda.function_name, tck_lambda.test_function_name].each do |function_name| params = "--function-name #{function_name} " << "--handler #{tck_lambda.handler} " << "--runtime #{tck_lambda.runtime} " << "--role #{tck_lambda.role} " << "--memory-size #{tck_lambda.memory_size} " << "--timeout #{tck_lambda.timeout} " << "--description \"#{tck_lambda.description}\" " << "--zip-file fileb://#{tck_lambda.zip_file}" cmd = "aws lambda create-function #{params}" puts cmd puts `#{cmd}` end end end end