rubyonjets/jets

Deploy of s3_event job fails on Custom::S3BucketConfiguration if not already deployed

Closed this issue · 1 comments

Checklist

  • Upgrade Jets: Are you using the latest version of Jets? This allows Jets to fix issues fast. There's a jets upgrade command that makes this a simple task. There's also an Upgrading Guide: http://rubyonjets.com/docs/upgrading/
  • Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.boltops.com
  • Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.

My Environment

Software Version
Operating System MacOS 14.2.1
Jets 5.0.9
Ruby 3.2.0 installed via asdf

Expected Behaviour

I am attempting to deploy s3_event job, for which I would expect S3 bucket + SNS topic + Lambda function and associated resources within Cloudformation stack.

Current Behavior

Cloudformation stack creation fails upon attempt to create S3BucketConfiguration.

Step-by-step reproduction instructions

Create new project. Do not deploy project.

jets new {project} --mode job

Add .tools-versions file

ruby 3.2.0

Generate new s3_event job

jets generate job {job name } --type s3

Update s3_event job with desired bucket name. I happened to make my bucket name the same as the project name. My file looked like...

class S3IngestJob < ApplicationJob
  s3_event "{same name as project}" # S3 bucket
  def perform
    puts "event #{JSON.dump(event)}"
    puts "s3_events #{JSON.dump(s3_events)}"
    puts "s3_objects #{JSON.dump(s3_objects)}"
  end
end

Run jets deploy

This fails with log entries as follows (*** represents redaction):

event: { "RequestType": "Create", "ServiceToken": "arn:aws:lambda:us-east-2:***:function:***-jets-s3_bucket_config", "ResponseURL": "https://cloudformation-custom-resource-response-useast2.s3.us-east-2.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-east-2%3A***%3Astack/i***-X7F069DJ018B/67b86b30-be04-11ee-a1d4-0af8fa8f40c5%7CS3BucketConfiguration%7C9b05a71b-49cc-4dcb-8379-e208b1de4d9d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240128T174142Z&X-Amz-SignedHeaders=host&X-Amz-Expires=7200&X-Amz-Credential=***%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Signature=5506a4257c949d76a6925882295c237b076c275206beb65507b950032fcd4bb7", "StackId": "arn:aws:cloudformation:us-east-2:***:stack/***-X7F069DJ018B/67b86b30-be04-11ee-a1d4-0af8fa8f40c5", "RequestId": "9b05a71b-49cc-4dcb-8379-e208b1de4d9d", "LogicalResourceId": "S3BucketConfiguration", "ResourceType": "Custom::S3BucketConfiguration", "ResourceProperties": { "ServiceToken": "arn:aws:lambda:us-east-2:***:function:***-jets-s3_bucket_config", "Bucket": "***", "NotificationConfiguration": { "TopicConfigurations": [ { "TopicArn": "arn:aws:sns:us-east-2:***:***-X7F069DJ018B-SnsTopic-j6ipRgj9Ezp3", "Events": [ "s3:ObjectCreated:*" ] } ] } } } context: "#" | context: "#" context.log_stream_name "2024/01/28/[$LATEST]b8c99782ea304c60bfd1e55bc60898c8" props: { "bucket": "***", "notification_configuration": { "topic_configurations": [ { "topic_arn": "arn:aws:sns:us-east-2:***:***-X7F069DJ018B-SnsTopic-j6ipRgj9Ezp3", "events": [ "s3:ObjectCreated:*" ] } ] } } ERROR The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. BACKTRACE: /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/seahorse/client/plugins/raise_response_errors.rb:17:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-s3-1.143.0/lib/aws-sdk-s3/plugins/sse_cpk.rb:24:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-s3-1.143.0/lib/aws-sdk-s3/plugins/dualstack.rb:21:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-s3-1.143.0/lib/aws-sdk-s3/plugins/accelerate.rb:43:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/aws-sdk-core/plugins/checksum_algorithm.rb:111:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:16:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/aws-sdk-core/plugins/idempotency_token.rb:19:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/aws-sdk-core/plugins/param_converter.rb:26:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/seahorse/client/plugins/request_callback.rb:89:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/aws-sdk-core/plugins/response_paging.rb:12:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/seahorse/client/plugins/response_target.rb:24:in `call' /opt/ruby/gems/3.2.0/gems/aws-sdk-core-3.191.0/lib/seahorse/client/request.rb:72:in `send_request' /opt/ruby/gems/3.2.0/gems/aws-sdk-s3-1.143.0/lib/aws-sdk-s3/client.rb:13645:in `put_bucket_notification_configuration' /var/task/handlers/shared/functions/jets/s3_bucket_config.rb:27:in `put' /var/task/handlers/shared/functions/jets/s3_bucket_config.rb:14:in `block in lambda_handler' /opt/ruby/gems/3.2.0/gems/cfn_response-0.2.0/lib/cfn_response.rb:17:in `response' /var/task/handlers/shared/functions/jets/s3_bucket_config.rb:7:in `lambda_handler' /var/runtime/lib/lambda_handler.rb:26:in `call_handler' /var/runtime/lib/runtime.rb:100:in `' Sending FAILED Status to CloudFormation

Code Sample

See above

Solution Suggestion

I was able to successfully deploy by:

  • tearing down the Cloudformation stack
  • deleting my s3_event job
  • running jets deploy with no job other than initial application_job.rb configured
  • re-adding my s3_event job, but with a different bucket name (not same as project name)
  • redeploying

This was my first ever usage of jets, so perhaps this is rookie error. It would however be helpful if documentation noted that s3_event jobs cannot have a bucket name that matches the project name or that the "bare" project must first be deployed (depending on whichever of these issues was actually the root cause).

@mikecbrant What was the bucket name exactly?

I am unable to repro with a random project and bucket name. application name: "my-app-#{random_string}".

I have a theory that this is not a jets issue per say but rather the bucket name you chose was not globally unique in your s3 region on AWS.

Assuming you create an application with the name "my-app", jets will deploy and create a deployment bucket with the following name: "my-app-{env}-{random_string}".

However it will not add modify your bucket name for events, so if any other person on AWS owns a "my-bucket" s3 bucket, it will fail to create because it is not globally unique. When you changed the bucket name to something not the application name you may have just happen to create a unique bucket name.