I'm using Amazon CloudFormation to describe my desired infrastructure in AWS cloud. In Amazon Secrets Manager I've created few variables, that are representing credentials for S3 as well as database access in my cluster. This secrets are injected into TaskDefinition like this:
Resources: {...}
TaskDefinition: {...}
Properties:
ContainerDefinitions:
- Name: !Ref ServiceName
Image: {...}
Environment:
-
Name: AWS_S3_SECRET_KEY
Value:
Fn::Join:
- ''
- - '{{resolve:secretsmanager:'
- Fn::ImportValue: !Ref S3CredentialsId
- ':SecretString:aws_s3_secret}}'
The problem with this approach is, that the TaskDefinition is not fetching any changes to the Amazon Secrets Manager automatically and therefore don't update the revision of the TaskDefinition -> all recently started containers are still referencing old values of the secret. That is why if I update the value of e.g. the aws_s3_secret
then this change will be not propagated to all of the existing and newly created containers in my Fargate cluster.
So far I've achieved this propagation with "dirty" approach - by adding some not existing environment variable to the TaskDefinition and applying this change to the cluster (I've uploaded the updated CloudFormation template of the service). Only after this action there was a new revision of the TaskDefinition created, that contained updated secrets value, as Fargate mentioned difference in the TaskDefinition description.
Therefore is my question: How to achieve this propagation of the secret changes into the TaskDefinition automatically?