I have a CI/CD structure on AWS with CodePipeline, CodeBuild, CodeDeploy, TaskDefinition, ECR, ECS green/blue deployment. I used AWS Fargate as a ECS service. I have Laravel and React apps which have seperated CodePipelines with green/blue.
I need a functionality to update BASE_URL variable which exist in .env file of React app. It should be green.mybackapp.com when front app is in green environment (to make sure that everything works correctly with my last version of backend). But it should be automatically changed to blue.mybackapp.com after I reroute all traffic to production. I think that one way to do it is using appspec hooks. But ECS Fargate appspec hooks only accept Lambda function (due to this docs). And I am not sure that it's possible to update .env file from Lambda function.
That's the my appspec.yaml:
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: <TASK_DEFINITION>
LoadBalancerInfo:
ContainerName: "nginx"
ContainerPort: 80
Hooks:
- AfterAllowTestTraffic: "scripts/AfterAllowTestTraffic.sh"
- BeforeAllowTraffic: "scripts/BeforeAllowTraffic.sh"
It doesn't work, because it only accept lambda function name, not .sh file which exist in source code. I can't find any article or issue which someone faced with this problem.
Need a solution to my problem, link, article or discussion where solved someone my problem.
I see, but still I need to change Front application BASE_URL env variable to mybackapp.com:8080 to send request to green environment while front application in green environment. And when front application go to blue environment it should send request to mybakcapp.com:80. So again I need something to update env variable.
I'm not very familiar with React apps, but are specifying the domain and port number absolutely necessary settings? If you don't have that, you can use Blue/Green deployment just by configuring the steps in the document below. https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-ecs-ecr-codedeploy.html