Sha256: d1965b7effc9478dd7685903b250918273a2f76513779cf031ce8a943e619ce3

Contents?: true

Size: 1.34 KB

Versions: 89

Compression:

Stored size: 1.34 KB

Contents

require "active_support/all"
require "aws-sdk-s3"
require "cfnresponse"
include Cfnresponse

def lambda_handler(event:, context:)
  # Print out debugging info immediately just in case
  puts "event: #{json_pretty(event)}"
  puts "context: #{json_pretty(context)}"

  if %w[Create Update].include?(event['RequestType'])
    properties = event["ResourceProperties"].dup
    # After deleting ServiceToken, the rest of the values is the bucket configuration properties.
    properties.delete("ServiceToken")
    configurator = BucketConfigurator.new
    configurator.put(properties)
  end

  send_response(event, context, "SUCCESS")

# We rescue all exceptions and send an message to CloudFormation so we dont have to
# wait for over an hour for the stack operation to timeout and rollback.
rescue Exception => e
  puts e.message
  puts e.backtrace
  sleep 10 # a little time for logs to be sent to CloudWatch
  send_response(event, context, "FAILED")
end

########################################################

class BucketConfigurator
  def put(props={})
    # all props including bucket gets passed from the Custom::S3BucketConfiguration resource
    props = props.deep_transform_keys { |k| k.to_s.underscore.to_sym }
    puts "props: #{JSON.dump(props)}"
    s3.put_bucket_notification_configuration(props)
  end

  def s3
    @s3 ||= Aws::S3::Client.new
  end
end

Version data entries

89 entries across 89 versions & 2 rubygems

Version Path
jets-1.9.13 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.12 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.11 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.10 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.9 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.8 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.7 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.6 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.5 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.4 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.3 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.2 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.1 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.9.0 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.8.14 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.8.13 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.8.12 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.8.11 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.8.10 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-1.8.9 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb