aws/aws-xray-daemon

AWS Credentials for Docker and Rails Application

dimitardanailov opened this issue · 1 comments

Greetings,

I'd like to discuss what's the best way for passing aws credentials

My application is Ruby on Rails

So far my Dockerfile uses:

# https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-ecs.html
RUN apt-get update && apt-get install -y --force-yes --no-install-recommends apt-transport-https curl ca-certificates wget && apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*
RUN wget https://s3.ap-southeast-1.amazonaws.com/aws-xray-assets.ap-southeast-1/xray-daemon/aws-xray-daemon-3.x.deb
RUN dpkg -i aws-xray-daemon-3.x.deb
ENTRYPOINT ["/usr/bin/xray", "--bind=0.0.0.0:2000", "--bind-tcp=0.0.0.0:2000"]
EXPOSE 2000/udp
EXPOSE 2000/tcp

Application setup:

# Gemfile
gem "aws-xray-sdk", "~> 0.13.0"

# config/initializers/aws_xray.rb
Rails.application.config.xray = {
  # default segment name generated by XRay middleware
  name: "webportal",
  patch: %I[net_http aws_sdk],
  # record db transactions as subsegments
  active_record: true
}

What's the best way to pass my aws credentials ?

To define credentials for your daemon in a docker container, you can follow these docs: https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon.html#xray-daemon-permissions

Basically you can either expose the AWS creds through environment variables in your Dockerfile or mount the ~/.aws/credentials file in your container.