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-2.3.19 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.18 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.17 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.16 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.15 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.14 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.13 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.12 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.11 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.10 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.9 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.8 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.7 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.6 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.5 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.4 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.3 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.2 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.1 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb
jets-2.3.0 lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb