It seems that I have a similar configuration to yours.
Deploy step in my configuration deploys cloudformation nested stack.
Some details about Deploy step:
- Name: Deploy
Actions:
- Name: Deploy
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ChangeSetName: Deploy
ActionMode: CREATE_UPDATE
StackName: !Sub ${AWS::StackName}-nested
Capabilities: CAPABILITY_NAMED_IAM
TemplatePath: Architecture-Template::service-ec2.yaml
RoleArn: !GetAtt CloudFormationExecutionRole.Arn
ParameterOverrides: !Sub |
{
"ImageURI" : { "Fn::GetParam" : [ "BuildOutput", "imageDetail.json", "ImageURI" ] },
"ApplicationRepoName": "${ApplicationRepoName}",
"VpcId": "${VpcId}",
"Cluster": "${Cluster}",
"ListenerArn": "${ListenerArn}",
"ServiceAssignPublicIP": "${ServiceAssignPublicIP}",
"ServiceDesiredCount": "${ServiceDesiredCount}",
"ServiceLoadBalancerPath": "${ServiceLoadBalancerPath}",
"ServiceSecurityGroups": "${ServiceSecurityGroups}",
"ServiceSubnets": "${ServiceSubnets}",
"TaskHostPort": "${TaskHostPort}",
"TaskContainerPort": "${TaskContainerPort}",
"TaskCpu": "${TaskCpu}",
"TaskMemory": "${TaskMemory}",
"TaskExecutionRoleArn": "${TaskExecutionRoleArn}",
"LoadBalancerPriority": "${LoadBalancerPriority}",
"TargetGroupHealthCheckPath": "${TargetGroupHealthCheckPath}",
"TargetGroupPort": "${TargetGroupPort}",
"TargetGroupHealthCheckPort": "${TargetGroupHealthCheckPort}",
"TagMaintainer": "${TagMaintainer}",
"TagEnvironment": "${TagEnvironment}",
"TagApi": "${TagApi}"
}
InputArtifacts:
- Name: Architecture-Template
- Name: BuildOutput
RunOrder: 1
As you can see I pass to the nested stack a set of parameters,
including the value from the
imageDetail.json
file, which contents is updated during the build step according
to the instructions in buildspec.yml configuration file.
Inside this file I define an image tag as:
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- echo $COMMIT_HASH
- IMAGE_TAG=${COMMIT_HASH:=latest}
Then I use this information to create an ImageURI and update imageDetail.json
configuration file
- printf '{"ImageURI":"%s:%s"}' $REPOSITORY_URI $IMAGE_TAG > imageDetail.json
This means that each new build should change this information,
that in turn is passed to the nested stack,
which should be updated because image definition is changed.
In my case the problem was related to the fact that I used latest
instead of the actual tag, as below (incorrect value, replace latest with actual tag)
- printf '{"ImageURI":"%s:%s"}' $REPOSITORY_URI latest > imageDetail.json
As soon as I fixed this line in my buildspec.yml the service was updated
each time when a new commit was identified by the CodePipeline.
In short:
To update a nested stack you should introduce some change to its configuration,
in my case id is related to the image tag in Elastic Container Registry