Skip to content

Instantly share code, notes, and snippets.

@metaskills
Created July 25, 2020 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metaskills/30bdfa3e1f6ba829fc3dbe19790e691c to your computer and use it in GitHub Desktop.
Save metaskills/30bdfa3e1f6ba829fc3dbe19790e691c to your computer and use it in GitHub Desktop.
Useful for Ruby/Docker SAM Projects
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