agent/api/statechange.go
func NewContainerStateChangeEvent(task *apitask.Task, cont *apicontainer.Container, reason string) (ContainerStateChange, error) {
	var event ContainerStateChange
	contKnownStatus := cont.GetKnownStatus()
	if !contKnownStatus.ShouldReportToBackend(cont.GetSteadyStateStatus()) {
		return event, errors.Errorf(
			"create container state change event api: status not recognized by ECS: %v",
			contKnownStatus)
	}
	if cont.IsInternal() {
		return event, errors.Errorf(
			"create container state change event api: internal container: %s",
			cont.Name)
	}
	if cont.GetSentStatus() >= contKnownStatus {
		return event, errors.Errorf(
			"create container state change event api: status [%s] already sent for container %s, task %s",
			contKnownStatus.String(), cont.Name, task.Arn)
	}

	if reason == "" && cont.ApplyingError != nil {
		reason = cont.ApplyingError.Error()
	}
	event = ContainerStateChange{
		TaskArn:       task.Arn,
		ContainerName: cont.Name,
		Status:        contKnownStatus.BackendStatus(cont.GetSteadyStateStatus()),
		ExitCode:      cont.GetKnownExitCode(),
		PortBindings:  cont.GetKnownPortBindings(),
		Reason:        reason,
		Container:     cont,
	}

	return event, nil
}
func NewContainerStateChangeEvent(task *apitask.Task, cont *apicontainer.Container, reason string) (ContainerStateChange, error) {
	var event ContainerStateChange
	contKnownStatus := cont.GetKnownStatus()
	if !contKnownStatus.ShouldReportToBackend(cont.GetSteadyStateStatus()) {
		return event, errors.Errorf(
			"create container state change event api: status not recognized by ECS: %v",
			contKnownStatus)
	}
	if cont.IsInternal() {
		return event, errors.Errorf(
			"create container state change event api: internal container: %s",
			cont.Name)
	}
	if cont.GetSentStatus() >= contKnownStatus {
		return event, errors.Errorf(
			"create container state change event api: status [%s] already sent for container %s, task %s",
			contKnownStatus.String(), cont.Name, task.Arn)
	}

	if reason == "" && cont.ApplyingError != nil {
		reason = cont.ApplyingError.Error()
	}
	event = ContainerStateChange{
		TaskArn:       task.Arn,
		ContainerName: cont.Name,
		Status:        contKnownStatus.BackendStatus(cont.GetSteadyStateStatus()),
		ExitCode:      cont.GetKnownExitCode(),
		PortBindings:  cont.GetKnownPortBindings(),
		Reason:        reason,
		Container:     cont,
	}

	return event, nil
}
// NewContainerStateChangeEvent creates a new container state change event