Created
July 25, 2020 02:55
-
-
Save metaskills/30bdfa3e1f6ba829fc3dbe19790e691c to your computer and use it in GitHub Desktop.
Useful for Ruby/Docker SAM Projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
require 'open-uri' | |
require 'aws-sdk-lambda' | |
class LayerDownloader | |
def download | |
File.open(zip_file, 'wb') do |f| | |
URI.open(location) { |zip| f.write(zip.read) } | |
end | |
end | |
def location | |
layer_info.content.location | |
end | |
def client | |
@client ||= Aws::Lambda::Client.new | |
end | |
def arn | |
@arn ||= cf_data['Mappings']['LayerArn'][region]['development'] | |
end | |
def layer_name | |
arn.split(':')[-2] | |
end | |
def version_number | |
arn.split(':')[-1] | |
end | |
def layer_info | |
@layer_info ||= client.get_layer_version( | |
layer_name: layer_name, | |
version_number: version_number | |
) | |
end | |
def region | |
ENV['AWS_REGION'] || 'us-east-1' | |
end | |
private | |
def cf_data | |
@cf_data ||= YAML.load(cf_yaml) | |
end | |
def cf_yaml | |
File.read "#{Dir.pwd}/template.yaml" | |
end | |
def zip_file | |
"#{Dir.pwd}/tmp/layer.zip" | |
end | |
end | |
LayerDownloader.new.download |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment