Class: Clairlune::Builder
- Inherits:
-
Object
- Object
- Clairlune::Builder
- Defined in:
- lib/clairlune.rb
Instance Method Summary collapse
-
#initialize(key:, bucket:, package_json:, function_name:, dest:, loglevel: 'info') ⇒ Builder
constructor
A new instance of Builder.
- #performe(loglevel: 'info') ⇒ Object
Constructor Details
#initialize(key:, bucket:, package_json:, function_name:, dest:, loglevel: 'info') ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 14 15 16 17 |
# File 'lib/clairlune.rb', line 9 def initialize(key:, bucket:, package_json:, function_name:, dest:, loglevel: 'info') @key = key @bucket = bucket @function_name = function_name @dest = dest @package_json = File.read(package_json) @logger = Logger.new(STDOUT) @logger.level = loglevel end |
Instance Method Details
#performe(loglevel: 'info') ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/clairlune.rb', line 19 def performe(loglevel: 'info') lambda_client = Aws::Lambda::Client.new @logger.info("Invoke build function: #{@function_name}") lambda_response = lambda_client.invoke( function_name: @function_name, payload: @package_json, invocation_type: 'RequestResponse', ) if lambda_response.data.status_code != 200 @logger.fatal('Returned status code is not 200 (Lambda).') return { success: false, description: 'Returned status code is not 200 (Lambda).', } end if JSON.load(lambda_response.data.payload)['status'] != 'success' @logger.fatal('Build is failed.') @logger.fatal(lambda_response.payload.read) return { success: false, description: lambda_response.payload.read, } end @logger.info("Download zipped npm module from: s3://#{@bucket}/#{@key}") s3_client = Aws::S3::Client.new File.open(@dest, 'w') do |file| s3_client.get_object(bucket: @bucket, key: @key) do |chunk| file.write(chunk) end end { success: true, file_path: @dest, description: 'success', } end |