Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.