How to make a AppConfig-managed configuration file on S3 available to an ECS service on Fargate?

0

Dear community,

I am trying to create a application with the following properties:

  1. the different components of the app will be shipped in docker containers and are hosted on ECR
  2. each container will have some configuration file hosted on S3 that will be updated dynamically during deployment
  3. the containers will be deployed with ECS on Amazon Fargate as a service

Currently, I am running a minimal version of the app in the following way:

  1. Uploaded an image to ECR that contains the config file due to copying (static config)
FROM eclipse-mosquitto
COPY ./mosquitto.conf /mosquitto/config/mosquitto.conf
  1. Defined a task with only this image and deployed it with ECS on Fargate
  2. Loaded the configuration file into an S3 Bucket
  3. Created a configuration profile on AppConfig

Here I got stuck. In my mind, several question arise:

  • How do I connect the config file in the container to the AppConfig managed file on S3?
  • When a configuration file is updated, can I hook into this process to restart the server inside the container?
  • Is using AppConfig appropriate here? Or would it be easier to restart the container and use a pull command from S3 on container startup to update the file?

I appreciate your help!

Best regards,

已提問 2 年前檢視次數 1103 次
1 個回答
1
已接受的答案

AppConfig may not be the best fit for this use case as described: it doesn't deliver configuration files to disk, but instead requires the application to call its API to refresh the configuration. (So you would then update your configuration in AppConfig, deploy it, and your application would, on next refresh*, receive the updated configuration.) Your application would need to be modified to call the AppConfig API instead of loading the configuration off disk. If you're happy reading Python, there's a sample library which you can dig in to to see how you might do it.

However, if you can arrange for a script to run inside your container, you could use the AWS CLI (or another language with an SDK, e.g. Python/boto3) to fetch the configuration from the API and store it in the file for your application, and then notify the application it should reload. An alternative for the last step would be to have the application monitor the modification time of the file, and reload when it is updated. AppConfig itself does not provide any native tooling to do this, I'm afraid, but the documentation has sample AWS CLI commands to get you started.

If neither of those options suit you, then the option you suggest in your third point may be the most straightforward to get you unblocked, although of course you lose some of AppConfig's benefits like validation and automatic rollbacks.

(* subject to your deployment rate)

profile pictureAWS
專家
James_S
已回答 2 年前
  • Thank you for the quick reply. I will try to modify my setup to work with the suggested "pull"-workflow as I really like the functionality provided by AppConfig. At least I am on the right track now!

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南